【问题标题】:GWT Compile Issues in Java (Google App Engine)Java 中的 GWT 编译问题(Google App Engine)
【发布时间】:2012-01-10 21:51:27
【问题描述】:

我在使用 Eclipse 的 Java 中使用 Google App 引擎时遇到了一个奇怪的编译问题。当我尝试 GWT 编译我的代码时,我收到如下错误:

Compiling module beer.SQLBeer
   Validating newly compiled units
      Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Finding entry point classes
      [ERROR] Errors in 'file:/C:/Users/Mark/workspace/SQLBeer/src/beer/client/SQLBeer.java'
         [ERROR] Line 12: The import com.google.appengine.api.rdbms cannot be resolved
         [ERROR] Line 13: The import com.google.apphosting cannot be resolved
         [ERROR] Line 14: The import com.google.cloud cannot be resolved
         [ERROR] Line 18: ServersServlet cannot be resolved to a type
         [ERROR] Line 22: The method doPost(HttpServletRequest, HttpServletResponse) of type SQLBeer must override or implement a supertype method
         [ERROR] Line 26: Connection cannot be resolved to a type
         [ERROR] Line 28: AppEngineDriver cannot be resolved to a type
         [ERROR] Line 29: Connection cannot be resolved to a type
      [ERROR] Unable to find type 'beer.client.SQLBeer'
         [ERROR] Hint: Previous compiler errors may have made this type unavailable
         [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Exception in thread "UnitWriteThread" 

我不确定为什么它无法解析导入,这使我无法将我的代码部署到 Google 应用引擎上。我觉得因为它不能很好地与我的导入配合使用,这与我收到错误的原因相同

[ERROR] Line 22: The method doPost(HttpServletRequest, HttpServletResponse) of type SQLBeer must override or implement a supertype method

我对使用 GWT 和 Google App Engine for Eclipse 非常陌生,但我试图访问我的团队使用 Google Cloud SQL 创建的数据库。如果我能克服这些错误,我觉得我越来越近了。

项目代码

package beer.client;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.rdbms.AppEngineDriver;
import com.google.apphosting.utils.servlet.ServersServlet;
import com.google.cloud.sql.jdbc.Connection;


@SuppressWarnings("serial")
public class SQLBeer extends ServersServlet {


    @Override 
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        PrintWriter out = resp.getWriter();
        Connection c = null;
        try {
            DriverManager.registerDriver(new AppEngineDriver());
            c = (Connection) DriverManager
                    .getConnection("jdbc:google:rdbms://asu.edu:cst433team1:team1db/mysql");
            String fname = req.getParameter("fname");
            String content = req.getParameter("content");

            /**
             * This code appears to do the web form fun
             */
//          if (fname == "" || content == "") {
//              out.println("<html><head></head><body>You are missing either a message or a name! Try again! Redirecting in 3 seconds...</body></html>");
//          } else {
//              String statement = "INSERT INTO entries (guestName, content) VALUES( ? , ? )";
//              PreparedStatement stmt = c.prepareStatement(statement);
//              stmt.setString(1, fname);
//              stmt.setString(2, content);
//              int success = 2;
//              success = stmt.executeUpdate();
//              if (success == 1) {
//                  out.println("<html><head></head><body>Success! Redirecting in 3 seconds...</body></html>");
//              } else if (success == 0) {
//                  out.println("<html><head></head><body>Failure! Please try again! Redirecting in 3 seconds...</body></html>");
//              }
//          }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (c != null)
                try {
                    c.close();
                } catch (SQLException ignore) {
                }
        }
        //resp.setHeader("Refresh", "3; url=/beer.jsp");
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}

有什么建议可以解决这些错误吗?我尝试了不同的 Imports,但它们似乎都在 GWT 编译器中导致了相同的问题。

编辑:我将扩展更改为 HttpServlet,现在错误有点不同

Compiling module beer.SQLBeer
   Validating newly compiled units
      Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   Finding entry point classes
      [ERROR] Errors in 'file:/C:/Users/Mark/workspace/SQLBeer/src/beer/client/SQLBeer.java'
         [ERROR] Line 13: The import com.google.appengine.api.rdbms cannot be resolved
         [ERROR] Line 14: The import com.google.cloud cannot be resolved
         [ERROR] Line 26: Connection cannot be resolved to a type
         [ERROR] Line 28: AppEngineDriver cannot be resolved to a type
         [ERROR] Line 29: Connection cannot be resolved to a type
      [ERROR] Unable to find type 'beer.client.SQLBeer'
         [ERROR] Hint: Previous compiler errors may have made this type unavailable
         [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Exception in thread "UnitWriteThread" java.lang.RuntimeException: Unable to read from byte cache

【问题讨论】:

    标签: java google-app-engine gwt


    【解决方案1】:

    首先,检查这不是类路径问题 - 这意味着您在 lib 目录和类路径中没有所有必需的 jar。

    如果失败,请确保此代码不是客户端(根据您的包名称猜测),它将被编译为 javascript。您不希望数据库连接代码发生这种情况,因此您应该在服务器端使用此代码。

    请参阅有关 Client sideServer side 代码的文档。

    【讨论】:

    • 我明白了!我一直在创建服务器类型代码,我认为它是基于客户端的。你不能告诉我一个新手吗? :) 现在我只需要弄清楚 JSP 和查询的问题...谢谢!
    • 没问题。不断尝试,不断学习。当你被卡住时,只要问!就是这样!
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 2015-02-08
    • 2014-08-09
    • 2011-07-29
    • 2017-05-09
    • 2011-10-29
    • 1970-01-01
    相关资源
    最近更新 更多