我在初始化阶段使用maven-properties-plugin从属性文件中读取一堆属性。
我还将jetty插件配置为将一些项目属性(包括上面读过的属性)设置为jetty的系统属性。
如果我将结果作为
运行mvn initialize jetty:run-war
它有效。
如果我只是说
mvn jetty:run-war
失败了。如何强制在命令行上指定的目标在包含初始化阶段的生命周期中运行?
答案 0 :(得分:1)
以下为我效劳。希望这可以帮助。 file:pom.xml
<profiles>
<profile>
<!-- mvn -Plocal -->
<id>local</id>
<build>
<defaultGoal>package</defaultGoal>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run-war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
答案 1 :(得分:0)
如果我只说
mvn jetty:run-war
则失败。
这不是我所经历的。如果您查看jetty:run-war
目标的文档,您会看到它:
在执行之前调用生命周期阶段
package
的执行。
因此,package
之前的所有阶段加上package
本身都会运行,因此,插件绑定到它们。事实上,通过以下POM:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>q2488581</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>q2488581 Maven Webapp</name>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
运行mvn jetty:run-war
会产生以下输出:
$ mvn jetty:run-war [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building q2488581 - Maven Webapp [INFO] task-segment: [jetty:run-war] [INFO] ------------------------------------------------------------------------ [INFO] Preparing jetty:run-war [INFO] [properties:read-project-properties {execution: default}] [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [compiler:compile {execution: default-compile}] [INFO] No sources to compile [INFO] [resources:testResources {execution: default-testResources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory /home/pascal/Projects/stackoverflow/q2488581/src/test/resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] No sources to compile [INFO] [surefire:test {execution: default-test}] [INFO] No tests to run. [INFO] [war:war {execution: default-war}] [INFO] Packaging webapp [INFO] Assembling webapp[q2488581] in [/home/pascal/Projects/stackoverflow/q2488581/target/q2488581] [INFO] Processing war project [INFO] Copying webapp resources[/home/pascal/Projects/stackoverflow/q2488581/src/main/webapp] [INFO] Webapp assembled in[76 msecs] [INFO] Building war: /home/pascal/Projects/stackoverflow/q2488581/target/q2488581.war [INFO] [jetty:run-war {execution: default-cli}] ...
正如我们所看到的,properties:read-project-properties
在initialize
阶段(process-resources
绑定到resources:resources
之前)按预期调用。{/ p>
换句话说,我无法重现你的问题(或者你应该更具体)。