【问题标题】:In Maven, how do I customize lifecycle phases?在 Maven 中,如何自定义生命周期阶段?
【发布时间】:2010-11-22 22:12:47
【问题描述】:

我在以下子模块中分离了一个 Java EE 项目:

  • 项目战争
  • 项目-ejb
  • 项目耳
  • 项目测试

我还有一个包含上述模块的根 pom。由于我在一个单独的项目中进行了测试,因此在前 3 个模块中运行测试阶段没有意义,因为编译或打包最后一个模块没有意义,因为它只包含其他 3 个模块的测试。我的问题是:如何从前 3 个模块中删除测试阶段以及如何从测试项目中删除其他阶段?

【问题讨论】:

    标签: java maven-2 jakarta-ee maven


    【解决方案1】:

    您可以通过设置不同的配置文件来做到这一点:http://maven.apache.org/guides/introduction/introduction-to-profiles.html

    exp:

        <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>
    

    您将在 cli 中使用 mvn -Pdeploywar -Denv=dev clean install 调用 deploywar 配置文件

    【讨论】:

    • 要注意的一点是,据我所知,配置文件在 maven 3 中将消失。
    • 希望它们能反向兼容...我们的大部分 pom 文件都是配置文件。
    • @CoolBeans - 正在消失的是在 POM 文件或设置文件之外定义的配置文件。
    • 你能举个例子说明我需要做什么吗?
    • 你现在的 pom 是什么样子的?
    猜你喜欢
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-05
    • 2016-08-05
    • 2011-07-31
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多