我是Java / Eclipse / GAE的新手,但遇到了这个错误。
java.lang.ClassNotFoundException: com.steve.HelloAppEngine
我刚刚创建了一个Google App Engine标准Java项目,并为Servlet添加了一个url映射(web.xml)。
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.steve.HelloAppEngine</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这是java文件的代码。
package com.steve;
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(
name = "HelloAppEngine",
urlPatterns = {"/hello"}
)
@SuppressWarnings("serial")
public class HelloAppEngine extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().print("Hello App Engine!\r\n");
}
}
Google App Engine Standard Java Project Image
多一点日志。请告诉我所需的其他信息。
2018-04-22 01:43:06.628:INFO::main: Logging initialized @1262ms
2018-04-22 01:43:06.978:INFO:oejs.Server:main: jetty-9.3.18.v20170406
2018-04-22 01:43:07.287:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=124ms
2018-04-22 01:43:07.822:WARN:oejs.BaseHolder:main:
java.lang.ClassNotFoundException: com.steve.HelloAppEngine
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:196)
我的项目结构(不是全部展开)(screenshot)
/demo
/src/main/java
com.steve
/com/steve/HelloAppEngine.java
com.steve.HelloAppEngine
com.steve.HelloAppEngine.doGet(HttpServletRequest, HttpServletResponse)
/demo/src/test/java
/demo/build
/demo/src
/main
/webapp
/META-INF
/META-INF/MANIFEST.MF
/WEB-INF
/lib
/jstl-1.2.jar
/appengine-web.xml
/web.xml
/favicon.ico
/index.html
/demo/src/test