7

我正在使用 maven-jetty-plugin 和 maven-failsafe-plugin 运行集成测试。这是我的配置:

   <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.7.1</version>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals>
                  <goal>integration-test</goal>
                </goals>
              </execution>
              <execution>
                <id>verify</id>
                <goals>
                  <goal>verify</goal>
                </goals>
              </execution>
             </executions>
        </plugin>

        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.26</version>
            <configuration>

                  <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                      <port>8080</port>
                      <maxIdleTime>3600000</maxIdleTime>
                    </connector>
                  </connectors>

                <contextPath>/</contextPath>
                <scanIntervalSeconds>3</scanIntervalSeconds>
                <scanTargetPatterns>
                    <scanTargetPattern>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <excludes>
                            <exclude>**/*.jsp</exclude>
                            <exclude>**/*.html</exclude>
                        </excludes>
                        <includes>
                            <include>**/*.page</include>
                            <include>**/*.properties</include>
                            <include>**/*.xml</include>
                        </includes>
                    </scanTargetPattern>
                </scanTargetPatterns>
            </configuration>
            <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                          <goal>run-war</goal>
                        </goals>
                        <configuration>
                          <scanIntervalSeconds>0</scanIntervalSeconds>
                          <daemon>true</daemon>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                          <goal>stop</goal>
                        </goals>
                    </execution>
          </executions>
        </plugin>

当我运行mvn clean install时,码头服务器启动,之后什么也没有发生(卡住了)。我日志中的最后一行是:[INFO] Started Jetty Server。当我按下 control-c 时,它会打印以下内容:

2013-04-25 15:24:16.315:INFO::Shutdown hook executing
2013-04-25 15:24:16.317:INFO::Stopped SelectChannelConnector@0.0.0.0:8080
2013-04-25 15:24:16.821:INFO:/ca-app:Shutting down log4j
2013-04-25 15:24:16.821:INFO:/ca-app:Closing Spring root WebApplicationContext
2013-04-25 15:24:22.108:INFO::Shutdown hook complete[INFO] 
Jetty server exiting.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.7.1:integration-test (default) @ my-app ---
[INFO] Failsafe report directory: my-app/target/failsafe-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-jetty-plugin:6.1.26:stop (stop-jetty) @ my-app ---
[INFO] 
[INFO] --- maven-failsafe-plugin:2.7.1:verify (default) @ my-app ---
[INFO] Killing Jetty
[INFO] Failsafe report directory: my-app/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ my-app ---
[INFO] Installing my-app/target/ca-app-0.1.5-SNAPSHOT.war to ~/.m2/....../my-app/0.1.5-SNAPSHOT/my-app-0.1.5-SNAPSHOT.war
[INFO] Installing my-app/pom.xml to ~/.m2/....../my-app/0.1.5-SNAPSHOT/my-app-0.1.5-SNAPSHOT.war
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:sources (install) @ my-app ---

为什么会卡住?当我按下 control-c 时,为什么它会执行其余的步骤?我该如何解决?

4

2 回答 2

1

尝试使用start而不是run-war

从 org\eclipse\jetty\jetty-maven-plugin\9.3.0.M2\jetty-maven-plugin-9.3.0.M2.jar!\org\eclipse\jetty\maven\plugin\AbstractJettyMojo.nonblocking 上的 javadoc


确定服务器在启动时是否阻塞。默认行为 (false) 将导致服务器在继续处理 Web 请求时暂停其他进程。这在启动服务器以交互使用它时很有用。这是jetty:run、jetty:run-war、jetty:run-war-exploded目标的行为。如果为真,服务器将不会阻止后续代码的执行。这是jetty:start的行为和jetty:deploy目标的默认行为。


于 2015-03-21T22:03:04.627 回答
0

所以为了启动码头添加运行:

<goals>
     <goal>stop</goal>
        <goal>start</goal>
</goals>

和整个:

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.2.10.v20150310</version>
    <configuration>
        <war>webapp/target/MyWar.war</war>
        <stopKey>fooKey</stopKey>
        <stopPort>8081</stopPort>
        <stopWait>1</stopWait>
        <httpConnector>
            <port>8888</port>
        </httpConnector>
    </configuration>
    <executions>
        <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>stop</goal>
                <goal>start</goal>
            </goals>
            <configuration>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <daemon>true</daemon>
                <stopKey>STOP</stopKey>
                <stopPort>8866</stopPort>
            </configuration>
        </execution>
        <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
            <configuration>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <daemon>true</daemon>
                <stopKey>STOP</stopKey>
                <stopPort>8866</stopPort>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2016-07-29T11:25:51.560 回答