Reputation: 4706
I use the jetty-maven-plugin for local development testing. What I want is from a single jetty:run command, start a bunch of jetty containers on separate ports as specified in the pom.xml -- I don't want to specify it within the war. My current plugin configuration block looks like ::
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-a/target/a.war</war>
<contextPath>/a</contextPath>
<allowNullPathInfo>true</allowNullPathInfo>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-b/target/b.war</war>
<contextPath>/b</contextPath>
<allowNullPathInfo>true</allowNullPathInfo>
</contextHandler>
</contextHandlers>
</configuration>
I know I can specify a -Djetty.port but that globally sets the port. The above example starts both wars in the same jetty container instance running on port 8080. Does anyone know a switch within contextHandler to set the port or how to do it if I have multiple instances of the entire plugin block? Every example I've searched for only has the option to set it in the jetty.xml file within the war which I don't want to do.
Upvotes: 1
Views: 1462
Reputation: 49187
It's possible if you name the connectors and context handlers
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<name>instance_8080</name>
</connector>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8081</port>
<name>instance_8081</name>
</connector>
</connectors>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-a/target/a.war</war>
<contextPath>/a</contextPath>
<connectorNames>
<item>instance_8080</item>
</connectorNames>
</contextHandler>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>${basedir}/service-b/target/b.war</war>
<contextPath>/b</contextPath>
<connectorNames>
<item>instance_8081</item>
</connectorNames>
</contextHandler>
</contextHandlers>
</configuration>
Note, this configuration is for org.mortbay.jetty:jetty-maven-plugin
.
Upvotes: 1
Reputation: 818
In your jetty maven plugin you can create multiple connectors
that can run on different ports. That's a first start.
I'm not sure offhand how or if those connector
blocks can run different wars. They can refer to different jetty.xml (although I've had nothing but trouble with jetty.xml)
Upvotes: 0