在没有WAR文件的情况下使用Jetty启动Java应用程序
我尝试通过本教程启动Jersey + Jetty + Nginx,但是我无法使用war文件.如何启动我的Java应用程序?
I try start Jersey + Jetty + Nginx via this tutorial and I cannot use war file. How can I start my java application?
我通过右键单击BackendServer.java启动应用程序,然后在IDEA中或在终端java -cp /home/example/backend/build/WEB-INF/lib/backend.jar:/home/example/backend/libs/* com.example.backend.BackendServer
中使用运行".
I start application by right click on BackendServer.java and click "Run" in IDEA or using in terminal java -cp /home/example/backend/build/WEB-INF/lib/backend.jar:/home/example/backend/libs/* com.example.backend.BackendServer
.
/opt/jetty/webapps/backend.xml
/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重定向到了码头,但是我不知道如何用码头来启动球衣应用程序...
What should be instead ???????
? Should I use embedded jetty in BackendServer.java? I know that I have redirect requests from nginx to jetty, but I don't understand how can I start jersey application with jetty...
链接的示例/教程和链接的较早版本的问题不兼容.
The linked example/tutorial and the linked earlier question are not compatible.
本教程适用于Jetty 6(现在已经过时了),并完全使用嵌入式jetty,并启用了部署和所有功能.
The tutorial is for Jetty 6 (now impossibly out of date), and uses embedded-jetty completely, with deployments and everything enabled.
您之前的问题设置了com.sun.net.httpserver.HttpServer
,这不是一回事.
Your prior question sets up a com.sun.net.httpserver.HttpServer
which is not the same thing.
resourceBase
是您可能要提供的任何Webapp内容的根目录.
resourceBase
is the root directory for any webapp content that you might want to serve.
由于使用的是简单的ContextHandler
,因此该目录应指向磁盘上的目录.
Since you are using a simple ContextHandler
, then that should point to a directory on your disk.
如果您使用的是WebAppContext
,则该目录应指向您的webapp基本目录(将包含WEB-INF/web.xml
或WEB-INF/classes
之类的可选文件)
If you were using a WebAppContext
, then that should point to your webapp base directory (where optional files like WEB-INF/web.xml
or WEB-INF/classes
would be)
您定义的ResourceHandler
应该使用ContextHandler.resourceBase
.
请注意,ResourceHandler
是用于最简单,最简单的静态文件服务.
如果您的Web客户端有执行缓存查找,恢复下载,部分下载或mime类型的控件的任何要求,请使用DefaultServlet
.
Be aware that ResourceHandler
is for the barest, most simplistic static file serving.
If you have any requirements from your web clients to perform cached lookups, resume downloads, partial downloads, or mime-type controls, then use a DefaultServlet
.
此外,如果您只需要嵌入式Jetty中的文件服务器,为什么还要使用具有基本ContextHandler
的XML部署?只需将其写入嵌入式码头服务中,将非常容易.
Also, if all you want is a file server in embedded jetty, why are you using an XML deployment with a basic ContextHandler
? That would be so much easier to just write into your embedded jetty service.
一些可能对您有用的嵌入式码头示例代码:
Some embedded jetty example code that might prove useful to you:
- 嵌入式Jetty中有多个DefaultServlet .
- 嵌入式Jetty中的简单Servlet + DefaultServlet -显示为什么在某些情况下
ResourceHandler
不是一个好的选择. - 具有JSP支持的嵌入式码头
- 4种将WebSocket与嵌入式Jetty结合使用的方式
- 使用支持Servlet 3.0功能的WAR/WebAppContext嵌入式码头
- 使用支持Servlet 3.1功能的WAR/WebAppContext嵌入式码头
- Multiple DefaultServlet's in embedded Jetty.
- Simple Servlet + DefaultServlet in embedded Jetty - shows why
ResourceHandler
isn't a good choice in some circumstances. - Embedded Jetty with JSP support
- 4 different ways to use WebSocket with Embedded Jetty
- Embedded Jetty using WAR/WebAppContext supporting Servlet 3.0 features
- Embedded Jetty using WAR/WebAppContext supporting Servlet 3.1 features