Java 如何用jetty.port覆盖jetty.xml
我正在使用maven jetty插件,并试图用-Djetty.port=8090覆盖我的jetty.xml设置,但它不起作用。只有当我从jetty.xml文件中删除连接器部分时,我才将端口设置为8090 因此: 连接器从端口8080开始 在没有连接器的情况下,从端口8090启动 问题是我需要配置接受器、统计数据和其他东西。我尝试只从连接器上卸下端口,但没有成功 我正在使用:Java 如何用jetty.port覆盖jetty.xml,java,maven,jetty,embedded-jetty,maven-jetty-plugin,Java,Maven,Jetty,Embedded Jetty,Maven Jetty Plugin,我正在使用maven jetty插件,并试图用-Djetty.port=8090覆盖我的jetty.xml设置,但它不起作用。只有当我从jetty.xml文件中删除连接器部分时,我才将端口设置为8090 因此: 连接器从端口8080开始 在没有连接器的情况下,从端口8090启动 问题是我需要配置接受器、统计数据和其他东西。我尝试只从连接器上卸下端口,但没有成功 我正在使用: JAVA 1.7_05 MAVEN 3.0.4 Jetty 8.1.4 Linux Ubuntu 12.04 64bits
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>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<maxIdleTime>3600000</maxIdleTime>
<port>${jetty.port}</port>
</connector>
org.mortbay.jetty
jetty maven插件
8.1.4.v20120524
福
9990
src/main/webapp/WEB-INF/jetty.xml
起动码头
跑
0
停靠码头
停止
Jetty.xml连接器配置:
<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>
<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>
300000
4.
假的
8443
20000
5000
提前谢谢
更新1:还尝试使用SystemProperty而不是jetty.xml中的属性。不起作用更新1:起作用。不知道为什么,但我也尝试了主机作为SystemProperty,并且成功了。然后我移除了主机,也开始工作 因此,最终修复工作jetty.xml连接器配置:
<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>
<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>
300000
4.
假的
8443
20000
5000
我也有同样的问题。修正:
在pom的属性部分,定义jetty.port:
<properties>
<jetty.port>8888</jetty.port>
....
</properties>
如果您使用./jetty.sh start命令启动服务器,它将从基本文件夹中的start.ini或start.d读取configure,请尝试更改其中的端口(jetty.port),然后重新启动服务器。只需删除“port”内的SystemProperty标记,并将新端口值放入“port”标记内:
同意。POM处的配置端口清晰且直接,这种方式对我来说与Jetty 9不起作用。设置端口不受尊重。系统属性确实有效。看其他评论。是的,我不敢相信他们从9号码头上拿走了。看来是时候降级了!如果读取器不想覆盖jetty.xml文件,则使用系统属性覆盖pom中的默认端口:
jetty.port${jetty.port}
前面的评论应为Jetty 9的公认答案,请参见: