java - 如何用 jetty.port 覆盖 jetty.xml

标签 java maven jetty embedded-jetty maven-jetty-plugin

我正在使用 maven-jetty-plugin 并尝试使用 -Djetty.port=8090 覆盖我的 jetty.xml 设置,但它不起作用。只有当我从 jetty.xml 文件中删除连接器部分时,我才能将端口设置为 8090。

所以:

 mvn jetty:run -Djetty.port=8090

连接器从 8080 端口开始

没有连接器从 8090 端口开始

问题是我需要配置接受器、统计数据和其他东西。我尝试仅从连接器上移除端口,但没有用。

我正在使用:

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 连接器配置文件:

<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:还尝试在 jetty.xml 中使用 SystemProperty 而不是 Property。没用

最佳答案

更新 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>

关于java - 如何用 jetty.port 覆盖 jetty.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11652058/

相关文章:

java - RESTful Web 服务使用 JSON 上传/下载大数据

java - 在 jetty 6 上部署 war 的问题

java - 如何确认客户端收到响应

java - 如何使用maven启动和停止jetty

java - Keycloak:从自定义端点 (SPI) 发送 AdminEvent

java - 文件存在但 java file.exists() 但返回 false

java - 如何将csv文件中的数据解析到容器中并搜索1个值并在java中检索其行上的其余值

java - maven-jar-plugin 文件过滤

java - 如何从Junit获取/src/main/resources?

java - Maven Java 项目中文件搜索中的 IntelliJ : Hide . 类文件