![](/img/trans.png)
[英]Deploying WAR file to Jetty: server is running, but application didn't start
[英]Start java application with jetty without WAR file
我尝试通过本教程启动Jersey + Jetty + Nginx, 但是我无法使用war文件。 如何启动我的Java应用程序?
我通过右键单击BackendServer.java来启动应用程序,然后在IDEA中单击“运行”或在终端java -cp /home/example/backend/build/WEB-INF/lib/backend.jar:/home/example/backend/libs/* com.example.backend.BackendServer
。
/opt/jetty/webapps/backend.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC
"-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<!--
Configure a custom context for serving javadoc as static resources
-->
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
<Set name="contextPath">/</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>??????????</Set>
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.ResourceHandler">
<Set name="welcomeFiles">
<Array type="String">
<Item>index.html</Item>
</Array>
</Set>
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
应该是什么,而不是???????
? 我应该在BackendServer.java中使用嵌入式码头吗? 我知道我已经将请求从Nginx重定向到了码头,但我不知道如何使用码头来启动球衣应用程序...
链接的示例/教程和链接的先前的问题不兼容。
本教程适用于Jetty 6(现在已经过时了),并且完全使用了嵌入式jetty,并启用了部署和所有功能。
您之前的问题设置了一个com.sun.net.httpserver.HttpServer
,它不是同一回事。
resourceBase
是您可能要提供的任何Webapp内容的根目录。
由于您使用的是简单的ContextHandler
,因此应该指向磁盘上的目录。
如果您使用的是WebAppContext
,则该目录应指向您的webapp基本目录(将包含WEB-INF/web.xml
或WEB-INF/classes
等可选文件)
您定义的ResourceHandler
应该使用ContextHandler.resourceBase
。
请注意, ResourceHandler
用于最简单,最简单的静态文件服务。 如果您的Web客户端对执行缓存的查找,恢复下载,部分下载或mime类型的控件有任何要求,请使用DefaultServlet
。
另外,如果您只需要嵌入式Jetty中的文件服务器,为什么还要使用带有基本ContextHandler
的XML部署? 只需将其写入嵌入式码头服务中,将非常容易。
一些可能对您有用的嵌入式码头示例代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.