How to override jetty.xml with jetty.port
Asked Answered
L

4

11

I'm using maven-jetty-plugin and trying to override my jetty.xml setting with the -Djetty.port=8090 but it's not working. Only when I remove the connector part from the jetty.xml file I get the port to be 8090.

So:

 mvn jetty:run -Djetty.port=8090

With the connector starts in port 8080

Without the connector starts in port 8090

Problem is I need to configure acceptors, stats and other stuff. I tried removing only the port from the connector but it didn't work.

I'm using:

JAVA 1.7_05
MAVEN 3.0.4
Jetty 8.1.4
Linux Ubuntu 12.04 64bits

Here's my pom.xml plugin configuration:

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.4.v20120524</version>
            <configuration>
                <stopKey>foo</stopKey>
                <stopPort>9990</stopPort>
                <jettyXml>src/main/webapp/WEB-INF/jetty.xml</jettyXml>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <!-- <phase>pre-integration-test</phase> -->
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <scanIntervalSeconds>0</scanIntervalSeconds>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <!-- <phase>post-integration-test</phase> -->
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
</plugin>

Jetty.xml connector conf:

<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><Property name="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8080"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">4</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
  </Arg>
</Call>

Thanks in advance!

UPDATE 1: Also tried using SystemProperty instead of Property in the jetty.xml. Did not work

Lashanda answered 25/7, 2012 at 14:29 Comment(2)
In case a reader doesn't want to override a jetty.xml-file, then using a System property to override the default port in the pom works: <configuration> <systemProperties> <systemProperty> <name>jetty.port</name> <value>${jetty.port}</value> </systemProperty> </systemProperties> </configuration> Globate
The previous comment should be the accepted answerHypnotic
L
7

UPDATE 1: did work. Don't know why but I tried it with the host also as SystemProperty and it worked. Then I removed host and worked also.

So final fix working jetty.xml connector conf:

<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host"><SystemProperty name="jetty.host" /></Set>
        <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
        <Set name="maxIdleTime">300000</Set>
        <Set name="Acceptors">4</Set>
        <Set name="statsOn">false</Set>
        <Set name="confidentialPort">8443</Set>
    <Set name="lowResourcesConnections">20000</Set>
    <Set name="lowResourcesMaxIdleTime">5000</Set>
      </New>
  </Arg>
</Call>
Lashanda answered 25/7, 2012 at 17:5 Comment(1)
For Jetty 9, see: git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/plain/…Segarra
R
6

I had the same problem. Fix:

In the properties section of the pom, define jetty.port:

<properties>
    <jetty.port>8888</jetty.port>
            ....
</properties>

In the plugin configuration:

<connectors>
    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <maxIdleTime>3600000</maxIdleTime>
        <port>${jetty.port}</port>
    </connector>

This enables to override the port on command line with

mvn -D jetty.port=9999 jetty:run
Roosevelt answered 1/2, 2013 at 14:49 Comment(3)
agree. config port at POM is clear and straight-forwardNez
This way didn't work with Jetty 9 for me. The set port isn't respected. System property did work. See other comment.Globate
Yeah, I can't believe they took that out from Jetty 9. Looks like it's time to downgrade!Dallman
S
0

if you are using ./jetty.sh start command to start the server, it read configure from start.ini or start.d in base folder, please try to change port (jetty.port) in that and restart the server.

Synchronize answered 26/3, 2014 at 9:12 Comment(0)
D
0

Just remove the SystemProperty markup inside "port", and put the new port value inside "port" markup:

enter image description here

Dialect answered 28/2, 2015 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.