maven-jetty-插件问题

发布于 2024-10-08 22:16:08 字数 7545 浏览 0 评论 0原文

我需要在模块测试之前启动jetty。示例:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jetty-test</groupId>
    <artifactId>jetty-test</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>1.0-beta-6</version>
            </extension>
        </extensions>
        <plugins>
                <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo>Hello world!</echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <executions>
                    <execution>
                        <id>start-webapp-for-module-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-webapp-for-module-tests</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <daemon>true</daemon>
                    <stopPort>8181</stopPort>
                    <stopKey>stop-webapp</stopKey>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

一切正常,但 maven-antrun-plugin (或测试编译阶段之前的任何其他插件)开始运行两次。我尝试使用 run-war、run-exploaded 或 deploy-war 目标。结果是一样的。

Maven 输出:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - jetty-test:jetty-test:war:1.0
[INFO]    task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: test-compile}]
[INFO] Executing tasks

main:
     **[echo] Hello world!**
[INFO] Executed tasks
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] Preparing jetty:run
[WARNING] Removing: run from forked lifecycle, to prevent recursive invocation.
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: test-compile}]
[INFO] Executing tasks

main:
     **[echo] Hello world!**
[INFO] Executed tasks
[INFO] [jetty:run {execution: start-webapp-for-module-tests}]
[INFO] Configuring Jetty for project: Unnamed - jetty-test:jetty-test:war:1.0
[INFO] Webapp source directory = /home/chardex/projects/untitled/jetty-test/src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes directory /home/chardex/projects/untitled/jetty-test/target/classes does not exist
2010-12-24 16:50:17.254:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /jetty-test
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = /home/chardex/projects/untitled/jetty-test/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /home/chardex/projects/untitled/jetty-test/src/main/webapp
[INFO] Starting jetty 6.1.26 ...
2010-12-24 16:50:17.316:INFO::jetty-6.1.26
2010-12-24 16:50:17.416:INFO::No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Started Jetty Server
[INFO] [jetty:stop {execution: stop-webapp-for-module-tests}]
2010-12-24 16:50:17.603:INFO::Started [email protected]:8080
[INFO] Stopping server 0
2010-12-24 16:50:17.637:INFO::Stopped [email protected]:8080
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[jetty-test] in [/home/chardex/projects/untitled/jetty-test/target/jetty-test-1.0]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/chardex/projects/untitled/jetty-test/src/main/webapp]
[INFO] Webapp assembled in[25 msecs]
[INFO] Building war: /home/chardex/projects/untitled/jetty-test/target/jetty-test-1.0.war
[INFO] [install:install {execution: default-install}]
...

我哪里错了?

谢谢。

I need to start jetty before module tests. Example:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jetty-test</groupId>
    <artifactId>jetty-test</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>1.0-beta-6</version>
            </extension>
        </extensions>
        <plugins>
                <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <echo>Hello world!</echo>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.26</version>
                <executions>
                    <execution>
                        <id>start-webapp-for-module-tests</id>
                        <phase>test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-webapp-for-module-tests</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <daemon>true</daemon>
                    <stopPort>8181</stopPort>
                    <stopKey>stop-webapp</stopKey>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Everything works, but maven-antrun-plugin (or any other plugin before test-compile phase) begins to run two times. I tried to use run-war, run-exploaded or deploy-war goals. Result is the same.

Maven output:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - jetty-test:jetty-test:war:1.0
[INFO]    task-segment: [deploy]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: test-compile}]
[INFO] Executing tasks

main:
     **[echo] Hello world!**
[INFO] Executed tasks
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] Preparing jetty:run
[WARNING] Removing: run from forked lifecycle, to prevent recursive invocation.
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/chardex/projects/untitled/jetty-test/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: test-compile}]
[INFO] Executing tasks

main:
     **[echo] Hello world!**
[INFO] Executed tasks
[INFO] [jetty:run {execution: start-webapp-for-module-tests}]
[INFO] Configuring Jetty for project: Unnamed - jetty-test:jetty-test:war:1.0
[INFO] Webapp source directory = /home/chardex/projects/untitled/jetty-test/src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes directory /home/chardex/projects/untitled/jetty-test/target/classes does not exist
2010-12-24 16:50:17.254:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Context path = /jetty-test
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = /home/chardex/projects/untitled/jetty-test/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /home/chardex/projects/untitled/jetty-test/src/main/webapp
[INFO] Starting jetty 6.1.26 ...
2010-12-24 16:50:17.316:INFO::jetty-6.1.26
2010-12-24 16:50:17.416:INFO::No Transaction manager found - if your webapp requires one, please configure one.
[INFO] Started Jetty Server
[INFO] [jetty:stop {execution: stop-webapp-for-module-tests}]
2010-12-24 16:50:17.603:INFO::Started [email protected]:8080
[INFO] Stopping server 0
2010-12-24 16:50:17.637:INFO::Stopped [email protected]:8080
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[jetty-test] in [/home/chardex/projects/untitled/jetty-test/target/jetty-test-1.0]
[INFO] Processing war project
[INFO] Copying webapp resources[/home/chardex/projects/untitled/jetty-test/src/main/webapp]
[INFO] Webapp assembled in[25 msecs]
[INFO] Building war: /home/chardex/projects/untitled/jetty-test/target/jetty-test-1.0.war
[INFO] [install:install {execution: default-install}]
...

Where I'm wrong?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

波浪屿的海角声 2024-10-15 22:16:08

根据 文档,对于 mvn jetty:run ,

这个目标在 Maven 上就地使用
项目无需首先要求
该项目被组装成一场战争,
节省开发时间
循环。该插件派生了一个并行
生命周期以确保“编译”
阶段之前已完成
调用码头。这意味着你做
不需要显式执行“mvn
首先编译”。这也意味着
“mvn clean jetty:run”将确保
之前完成了完整的全新编译
调用 Jetty。

这解释了这种行为。

According to the documentation, for mvn jetty:run,

This goal is used in-situ on a Maven
project without first requiring that
the project is assembled into a war,
saving time during the development
cycle. The plugin forks a parallel
lifecycle to ensure that the "compile"
phase has been completed before
invoking Jetty. This means that you do
not need to explicity execute a "mvn
compile" first. It also means that a
"mvn clean jetty:run" will ensure that
a full fresh compile is done before
invoking Jetty.

This explains the behavior.

雪花飘飘的天空 2024-10-15 22:16:08

应该有一个单独的目标,它可以做同样的事情,但不会分叉生命周期。当插件作为构建生命周期中的一个步骤运行时,不可能不执行编译阶段和所有其他阶段,因此所有内容都会运行两次。创建错误:http://jira.codehaus.org/browse/JETTY-1365。错误已作为重复项移至 https://jira.codehaus.org/browse/JETTY-1405。他们表示无法重现该问题,需要特定的测试用例。不确定我什么时候能做到这一点,但如果有人有一个使用 maven-jetty-plugin 的简单战争项目来演示这个问题,他们可以将其上传到 JIRA 票证中吗?

There should be a separate goal which does the same thing but does not fork the lifecycle. It's impossible not to execute the compile phase and all other phases when the plugin is run as a step in the build lifecycle, so everything is run twice. Bug created: http://jira.codehaus.org/browse/JETTY-1365. Bug moved as a duplicate to https://jira.codehaus.org/browse/JETTY-1405. They said they couldn't reproduce the problem and need a specific test case. Not sure when I can get to this, but if someone has a simple war project using the maven-jetty-plugin which demonstrates the issue, can they please upload it to the JIRA ticket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文