java 在不同端口的 Jetty 中分离 web 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2132098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Separate webapps in Jetty on different ports
提问by Lars Tackmann
I need the following setup.
我需要以下设置。
- Jetty must listen on port 8080and 9090
- Each port must have its own separate applications (i.e. webapp1runs on 8080and webapp2on 9090). The web-apps should only be accessible on their designated ports (i.e. webapp2must not! be available on port 8080).
- Jetty 必须监听8080和9090端口
- 每个端口都必须有自己独立的应用程序(即webapp1在8080上运行,而webapp2在9090上运行)。web-apps 应该只能在它们指定的端口上访问(即webapp2不能!在端口8080上可用)。
I have successfully added extra connectorsto etc/jetty.xml so it now uses port 8080 and 9090. I have also added extra handlersso it now pick ups webaps from multiple directories (dir1/webapp1 and dir2/webapp2).
我已经成功地向 etc/jetty.xml添加了额外的连接器,因此它现在使用端口 8080 和 9090。我还添加了额外的处理程序,因此它现在可以从多个目录(dir1/webapp1 和 dir2/webapp2)中获取 webap。
My problem is this: jetty deployes all webapps found by each handler to every connector (i.e. every port) and thus webapp1and webapp2both becomes accessible on port 8080and 9090.
我的问题是:jetty 将每个处理程序找到的所有 webapp 部署到每个连接器(即每个端口),因此webapp1和webapp2都可以在端口8080和9090上访问。
I need a way to ensures that handler1(handles dir1/webapp1) is only designated to connector1(listens on port 8080) and equally for connector2to only pick up handler2(handles dir2/webapp2) on port 9090.
我需要一种方法来确保handler1(处理 dir1/webapp1)仅指定给connector1(侦听端口 8080),同样让connector2仅在端口9090上接收handler2(处理 dir2/webapp2)。
Is there a way of accomplishing this?
有没有办法做到这一点?
回答by Stephen Denne
Jetty documentation shows two methods.
The first configures two separate server instances, and starts them both by supplying the two configuration file names on the command line.
第一个配置两个单独的服务器实例,并通过在命令行上提供两个配置文件名来启动它们。
The second method uses names for the two connectors, and each application context names the connectors it will use.
第二种方法使用两个连接器的名称,每个应用程序上下文命名它将使用的连接器。
回答by Timothy
You are basically going to create two instances in the same JVM.
您基本上将在同一个 JVM 中创建两个实例。
Create two .xml files, and in each of the .xml files, specify:
创建两个 .xml 文件,并在每个 .xml 文件中指定:
...
<Set name="port">XXXX</Set>
...
<New id="webAppX" class="org.mortbay.jetty.webapp.WebAppContext">
<Arg><Ref id="Contexts"/></Arg>
<Arg><SystemProperty name="jetty.home"/>/webapps/X</Arg>
<Arg>/webappX</Arg>
...
</New>
...
[make sure you replace the X values in the appropriate xml files.]
[确保替换相应 xml 文件中的 X 值。]
Start Jetty with two instances in the same JVM, like this:
在同一个 JVM 中使用两个实例启动 Jetty,如下所示:
java -jar start.jar webapp1.xml webapp2.xml
回答by Thomas L?tzer
Why don't you use two Jetty installations, if you want to separate the apps?
如果要分离应用程序,为什么不使用两个 Jetty 安装?

