【问题标题】:How to start and stop jetty server during a building in Maven如何在 Maven 构建期间启动和停止码头服务器
【发布时间】:2016-05-11 20:11:00
【问题描述】:

我仍然遇到问题如何在 Maven 中配置码头插件,以便能够使用 maven-surefire-plugin 启动它运行测试,然后停止码头服务器。到目前为止,它只是运行码头并等待并且它不会继续。另一个问题是插件何时应该是 jetty-maven-plugin 或 maven-jetty-plugin。我没有他们之间的区别。无论如何,这里是我的 pom.xml 的摘录。

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <!--version>9.2.11.v20150529</version-->
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webApp>
                    <contextPath>/hellojavaworld</contextPath>           
                </webApp>    
                <war>c:\apache-tomcat-7.0.64\webapps\hellojavaworld.war</war>
                <stopPort>9966</stopPort>
                <stopKey>foo</stopKey>
            </configuration>

            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <!--configuration>
                        <daemon>true</daemon>
                    </configuration-->
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <excludes>
                    <exclude>*.java</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <excludes>
                            <exclude>none</exclude>
                        </excludes>
                        <includes>
                            <include>*.java</include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
</plugin>

在控制台中只是:

[INFO] 已启动 Jetty 服务器

[INFO] 每隔 10 秒启动一次扫描仪。

我希望它启动码头、运行测试(需要 servlet 容器)、停止码头并编写 BUILD SUCCESSFUL。

有人有什么建议吗? 提前致谢。

【问题讨论】:

标签: maven jetty surefire


【解决方案1】:

问题是必须指定标签&lt;daemon&gt;&lt;/daemon&gt;。在我的情况下被注释掉了。 jetty maven 插件的另一个好来源是http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin

【讨论】:

  • 除了&lt;daemon&gt; 配置之外还有更多内容,您应该使用start,而不是run
【解决方案2】:

我在使用 9.2.2.v20140723 版本的 jetty 插件时遇到了同样的问题。升级到 9.2.16.v20160414 后,maven 继续进行集成测试,并在集成测试后阶段停止码头服务器。

【讨论】:

    猜你喜欢
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2017-09-09
    • 1970-01-01
    • 2014-09-11
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多