我已将 Java EE 项目分为以下子模块:
- 项目战
- 项目-ejb
- 项目耳朵
- 项目测试
我还有一个根 pom,其中包含上述模块。由于我在一个单独的项目中进行了测试,因此在前 3 个模块中运行测试阶段是没有意义的,因为编译或打包最后一个模块是没有意义的,因为它只包含其他 3 个模块的测试。我的问题是:如何从前 3 个模块中删除测试阶段以及如何从测试项目中删除其他阶段?
最佳答案
您可以通过设置不同的配置文件来做到这一点:http://maven.apache.org/guides/introduction/introduction-to-profiles.html
经验:
<profile>
<id>deploywar</id>
<build>
<plugins>
<plugin>
<groupId>net.fpic</groupId>
<artifactId>tomcat-deployer-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>pos</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<host>${deploymentManagerRestHost}</host>
<port>${deploymentManagerRestPort}</port>
<username>${deploymentManagerRestUsername}</username>
<password>${deploymentManagerRestPassword}</password>
<artifactSource>
address/target/addressservice.war
</artifactSource>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- Defines the QA deployment information -->
<profile>
<id>qa</id>
<activation>
<property>
<name>env</name>
<value>qa</value>
</property>
</activation>
<properties>
<deploymentManagerRestHost>10.50.50.50</deploymentManagerRestHost>
<deploymentManagerRestPort>58090</deploymentManagerRestPort>
<deploymentManagerRestUsername>
myotherusername
</deploymentManagerRestUsername>
<deploymentManagerRestPassword>
myotherpassword
</deploymentManagerRestPassword>
</properties>
</profile>
您可以使用mvn -Pdeploywar -Denv=dev clean install
在cli中调用deploywar配置文件
关于java - 在 Maven 中,如何自定义生命周期阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4250697/