2012-07-25 40 views
11

我正在使用maven-jetty-plugin並試圖用-Djetty.port = 8090覆蓋我的jetty.xml設置,但它不工作。只有當我從文件的jetty.xml我得到移除連接部分的端口是8090如何用jetty.port覆蓋jetty.xml

所以:

mvn jetty:run -Djetty.port=8090 

與連接器端口8080

開始,沒有連接器啓動端口8090

問題是我需要配置acceptors,stats和其他東西。我試着從連接器上只移除端口,但它不起作用。

我使用:

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

這裏是我的pom.xml插件配置:

<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連接器的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> 

在此先感謝!

更新1:也嘗試使用SystemProperty而不是Jetty.xml中的屬性。沒有工作

+2

如果讀者不希望覆蓋指定一個jetty.xml文件,然後用系統屬性覆蓋默認端口在POM中的工作原理: '<配置> \t \t \t 碼頭。端口 \t \t $ {jetty.port} \t ' – MiB 2013-12-22 02:34:17

+0

的之前的評論應接受的答案 – 2014-05-23 10:56:03

回答

7

更新1:做了工作。不知道爲什麼,但我與主機一起嘗試它作爲SystemProperty,它的工作。然後我刪除了主持人,也工作。

所以最終的修復工作的jetty.xml連接器的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> 
+4

對於碼頭9,參見:HTTP:/ /git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/plain/jetty-server/src/main/config/etc/jetty-http.xml – 2015-01-21 23:08:42

5

我有同樣的問題。修正:

在POM的特性部分中,定義jetty.port:

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

在插件配置:

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

這使得能夠重寫命令行上的端口與

mvn -D jetty.port=9999 jetty:run 
+0

同意。 POM的配置端口清晰而直接 – 2013-12-19 03:37:25

+2

這種方式對我來說不適用於Jetty 9。設置的端口不受尊重。系統屬性確實有效。查看其他評論。 – MiB 2013-12-22 02:40:22

+2

是的,我不能相信他們從碼頭9拿走了它。看起來是時候降級了! – CorayThan 2014-03-18 23:39:26

0

如果您使用./jetty.sh start命令啓動服務器,它會從start.i中讀取配置ni或start.d在基本文件夾中,請嘗試更改端口(jetty.port)並重新啓動服務器。

0

只需卸下SystemProperty標記裏面的「端口」,把裏面的「口」標記的新的端口值:

enter image description here