从命令行部署一个简单的 HttpServlet 到 TomEE
Deploying a simple HttpServlet to TomEE from the command line
我正在尝试使用命令行将一个非常简单的 HttpServlet 部署到 TomEE 1.7.2,但我没有运气。代码如下所示:
@WebServlet("/HttpServlet")
public class SimpleHttpServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello Servlet Get</h1>");
out.println("</body>");
out.println("</html>");
}
}
我使用以下命令编译 class:
javac -cp "$TOMEE/lib/*" SimpleHttpServlet.java
一切看起来都不错,因为我只得到以下 warning:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.apache.openjpa.persistence.meta.AnnotationProcessor6' less than -source '1.8'
1 warning
要创建 war,我执行以下操作:
jar cf SimpleHttpServlet.war SimpleHttpServlet.class
我使用 bin/startup.sh
启动 TomEE,并使用 war 部署我的 war:
bin/tomee.sh deploy path/to/my/SimpleHttpServlet.war
我得到以下输出:
deploying /.../SimpleHttpServlet.war
Nov 05, 2015 5:39:50 PM org.apache.openejb.client.EventLogger log
INFO: RemoteInitialContextCreated{providerUri=http://localhost:8080/tomee/ejb}
Application deployed successfully at "/.../SimpleHttpServlet.war"
App(id=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
EjbJar(id=SimpleHttpServlet, path=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
WebApp(context-root=/SimpleHttpServlet, id=SimpleHttpServlet, path=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
如果我去 http://localhost:8080/manager/html I can see my war and everything looks okay. However, when I go to http://localhost:8080/SimpleHttpServlet/HttpServlet 我会从 TomEE 收到 404:
HTTP Status 404 - /SimpleHttpServlet/HttpServlet/
type Status report
message /SimpleHttpServlet/HttpServlet/
description The requested resource is not available.
Apache Tomcat (TomEE)/7.0.62 (1.7.2)
据我了解,使用 @WebServlet
时 web.xml
不是强制性的。我错过了什么?
谢谢!
nyg
您 war file 的布局不正确。您的 servlet 的 class 文件现在位于 /
中,但必须位于 /WEB-INF/classes
.
中
我正在尝试使用命令行将一个非常简单的 HttpServlet 部署到 TomEE 1.7.2,但我没有运气。代码如下所示:
@WebServlet("/HttpServlet")
public class SimpleHttpServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello Servlet Get</h1>");
out.println("</body>");
out.println("</html>");
}
}
我使用以下命令编译 class:
javac -cp "$TOMEE/lib/*" SimpleHttpServlet.java
一切看起来都不错,因为我只得到以下 warning:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.apache.openjpa.persistence.meta.AnnotationProcessor6' less than -source '1.8'
1 warning
要创建 war,我执行以下操作:
jar cf SimpleHttpServlet.war SimpleHttpServlet.class
我使用 bin/startup.sh
启动 TomEE,并使用 war 部署我的 war:
bin/tomee.sh deploy path/to/my/SimpleHttpServlet.war
我得到以下输出:
deploying /.../SimpleHttpServlet.war
Nov 05, 2015 5:39:50 PM org.apache.openejb.client.EventLogger log
INFO: RemoteInitialContextCreated{providerUri=http://localhost:8080/tomee/ejb}
Application deployed successfully at "/.../SimpleHttpServlet.war"
App(id=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
EjbJar(id=SimpleHttpServlet, path=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
WebApp(context-root=/SimpleHttpServlet, id=SimpleHttpServlet, path=/.../apache-tomee-plus-1.7.2/apps/SimpleHttpServlet)
如果我去 http://localhost:8080/manager/html I can see my war and everything looks okay. However, when I go to http://localhost:8080/SimpleHttpServlet/HttpServlet 我会从 TomEE 收到 404:
HTTP Status 404 - /SimpleHttpServlet/HttpServlet/
type Status report
message /SimpleHttpServlet/HttpServlet/
description The requested resource is not available.
Apache Tomcat (TomEE)/7.0.62 (1.7.2)
据我了解,使用 @WebServlet
时 web.xml
不是强制性的。我错过了什么?
谢谢!
nyg
您 war file 的布局不正确。您的 servlet 的 class 文件现在位于 /
中,但必须位于 /WEB-INF/classes
.