8

我正在开发一个集成测试套件,我有一个问题要问你。

我的父 pom 定义了 jetty 插件的使用,其目标是:run-war。我需要通过命令行更改码头监听的端口。例如,这可以通过传递 -Djetty.port=8099 来实现。

在子项目中,我需要使用此端口号为一些 SOAP 测试配置端点,这些测试需要在 jetty 托管的服务上运行。

如果我在端点配置中的子 pom 中使用 ${jetty.port} ,如果并且仅当我在调用 maven 时显式传递 -Djetty.port 时,它才能正常工作。

在我的孩子 pom 中:


<endpoint>http://127.0.0.1:${jetty.port}/{artifactId}<endpoint>

我需要用 8080 填充 jetty.port,如果 -Djetty.port 没有显式传递,这是码头的默认值,如果指定了命令行参数,仍然会捕获任何其他端口值。

4

2 回答 2

9

使用属性部分,并添加一个带有默认值的 jetty.port 属性:

<properties>
  <jetty.port>8080</jetty.port>
</properties>
于 2010-07-26T11:45:14.703 回答
8

配置 Maven 码头插件:

    <plugins>

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1H.14.1</version>
            <configuration>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>8085</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
             </configuration>
        </plugin>
    </plugins>

如果要使用较新版本的 jetty 插件,请使用以下配置:

来自http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html

您可以改为在标准 jetty xml 配置文件中配置连接器,并将其位置放入 jettyXml 参数中。请注意,从 jetty-9.0 开始,不再可以直接在 pom.xml 中配置 https 连接器:您需要使用 jetty xml 配置文件来执行此操作
就像是:

    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.0.5.v20130815</version>
        <configuration>
            <jettyXml>src/main/resources/jetty.xml</jettyXml>
            <webApp>
                <contextPath>/yourCtxPath</contextPath>
            </webApp>
        </configuration>
    </plugin>

可以使用 jetty.xml 文件内容来解决问题:


<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Call id="httpsConnector" name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ServerConnector">
        <Arg name="server"><Ref refid="Server" /></Arg>
          <Set name="host"><Property name="jetty.host" /></Set>
          <Set name="port"><Property name="jetty.port" default="8085" /></Set>
          <Set name="idleTimeout">30000</Set>
        </New>
    </Arg>
  </Call>

</Configure>

查看 'mvn jetty:run' 之后的日志,最后应显示如下内容:
2013-09-05 09:49:05.047:INFO:oejs.ServerConnector:main: Started ServerConnector@a6e9cb4{HTTP/1.1}{0.0. 0.0: 8085 }

对于此版本的插件,您将需要使用 maven 3 和 java 7。

于 2013-07-21T08:43:31.017 回答