我在使用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
答案 0 :(得分:5)
首先,检查这不是类路径问题 - 这意味着你没有在lib目录和类路径中拥有所有必需的jar。
如果失败,请确保此代码不是客户端(从您的软件包名称猜测),这将编译为javascript。您不希望这种情况发生在数据库连接代码中,因此您应该在服务器端使用此代码。
请参阅Client side上的文档&amp; Server side代码。