Luk*_*ský 36 maven-2 maven-jetty-plugin
我正在尝试将Maven WAR项目拆分为两个模块,以便我可以使用命令行工具构建单独的JAR文件.结果具有以下结构:
pom.xml(包装pom,有两个模块)project-jar/
pom.xml(包装jar)project-war/
pom.xml(包装war,取决于project-jar)如果我mvn从root 运行命令,一切正常.我想继续使用mvn jetty:run,但为此我需要在WAR子项目中执行命令.如果我这样做,找不到project-jar子项目,所以它不会运行.即使mvn jetty:run-war在target目录中完全组装的WAR文件失败,因为它首先尝试"构建"项目.我只是通过安装project-jar到本地Maven存储库来设法使它工作,这不是很好.
有没有办法在多模块Maven配置中使用Jetty插件?
Pat*_*ick 29
在war模块(project-war)中创建一个配置文件.在此配置文件中,配置jetty以附加到生命周期阶段并run明确执行目标.现在,当maven从启用了该配置文件的顶层项目运行时,它将调用jetty:run并具有姐妹模块依赖性解析(从顶层项目执行maven命令时正常).
示例配置放置在web模块(project-war)的pom.xml中时,会安排jetty:run在该test阶段执行.(你可以选择另一个阶段,但要确保它在之后compile.)
从顶层运行:mvn test -Pjetty-run或mvn test -DskipTests=true -Pjetty-run.这将根据需要编译依赖项并使它们可用但调用jetty:在正确的模块中运行.
<profiles>
...
<!-- With this profile, jetty will run during the "test" phase -->
<profile>
<id>jetty-run</id>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.1.6.v20100715</version>
<configuration>
...
<webAppSourceDirectory>
${project.build.directory}/${project.build.finalName}
</webAppSourceDirectory>
...
</configuration>
<executions>
<execution>
<id>jetty-run</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
...
</profiles>
Run Code Online (Sandbox Code Playgroud)
Pas*_*ent 11
没有神奇的解决方案,我所知道的唯一一个有点hacky并且依赖于extraClasspath可以用来相对地声明额外类目录的元素.像这样(来自JETTY-662):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.0.1.v20091125</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/my-context</contextPath>
<extraClasspath>target/classes;../my-jar-dependency/target/classes</extraClasspath>
</webAppConfig>
<scanTargets>
<scanTarget>../my-jar-dependency/target/classes</scanTarget>
</scanTargets>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14603 次 |
| 最近记录: |