开发者

Separate webapps in Jetty on different ports

开发者 https://www.devze.com 2022-12-17 06:19 出处:网络
I need the following setup. Jetty must listen on port 8080 and 9090 Each port must have its own separate applications (i.e. webapp1 runs on 8080 and webapp2 on 9090). The web-apps should only be acc

I need the following setup.

  • Jetty must listen on port 8080 and 9090
  • Each port must have its own separate applications (i.e. webapp1 runs on 8080 and webapp2 on 9090). The web-apps should only be accessible on their designated ports (i.e. webapp2 must not! be available on port 80开发者_运维技巧80).

I have successfully added extra connectors to etc/jetty.xml so it now uses port 8080 and 9090. I have also added extra handlers so it now pick ups webaps from multiple directories (dir1/webapp1 and dir2/webapp2).

My problem is this: jetty deployes all webapps found by each handler to every connector (i.e. every port) and thus webapp1 and webapp2 both becomes accessible on port 8080 and 9090.

I need a way to ensures that handler1 (handles dir1/webapp1) is only designated to connector1 (listens on port 8080) and equally for connector2 to only pick up handler2 (handles dir2/webapp2) on port 9090.

Is there a way of accomplishing this?


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.


You are basically going to create two instances in the same JVM.

Create two .xml files, and in each of the .xml files, specify:

...
<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.]

Start Jetty with two instances in the same JVM, like this:

java -jar start.jar webapp1.xml webapp2.xml


Why don't you use two Jetty installations, if you want to separate the apps?

0

精彩评论

暂无评论...
验证码 换一张
取 消