首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven-jetty-plugin问题

maven-jetty-plugin问题
EN

Stack Overflow用户
提问于 2010-12-24 22:13:11
回答 2查看 3.8K关注 0票数 0

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

代码语言:javascript
复制
<?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输出:

代码语言:javascript
复制
[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 SelectChannelConnector@0.0.0.0:8080
[INFO] Stopping server 0
2010-12-24 16:50:17.637:INFO::Stopped SelectChannelConnector@0.0.0.0: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}]
...

我哪里错了?

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2010-12-25 10:33:07

根据documentation的说法,对于mvn jetty:run

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

这就解释了这种行为。

票数 2
EN

Stack Overflow用户

发布于 2011-04-15 05:31:19

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4526773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档