【问题标题】:Maven: How to activate profile based on whether child module contains a file?Maven:如何根据子模块是否包含文件来激活配置文件?
【发布时间】:2014-02-27 05:32:18
【问题描述】:

我在 Mac 10.9.1 上使用 Maven 3.1.1。我想根据某些子模块是否包含文件来激活配置文件。我已经尝试了以下

    <profile>
        <id>deploy-war-to-jboss</id>
        <activation>
            <file>
                <exists>${session.executionRootDirectory}/src/main/webapp/WEB-INF/web.xml</exists>
            </file>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jboss.as.plugins</groupId>
                    <artifactId>jboss-as-maven-plugin</artifactId>
                    <version>${jboss.maven.plugin.version}</version>
                    <configuration>
                        <hostname>${jboss.remote.hostname}</hostname>
                        <port>${jboss.remote.port}</port>
                    </configuration>
                    <executions>
                        <execution>
                            <id>deploy-to-jboss</id>
                            <phase>install</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

但在运行“mvm clean install”时,这个配置文件并没有被激活,尽管我已经验证了有问题的子模块包含该文件。我也试过 ${project.basedir} 没有运气。任何想法我如何做到这一点?

【问题讨论】:

    标签: maven profile file-exists activation


    【解决方案1】:

    既然你在父 POM 中定义了配置文件(我猜)你应该试试这个

    ${basedir}/name-of-your-child-module//src/main/webapp/WEB-INF/web.xml
    

    此外,您应该尝试running Maven in debug mode 以在运行时获取更多信息:

    mvm -X clean install
    

    【讨论】:

    • 我有几个满足条件的子模块。我在我的个人资料中想说的是,如果子模块有一个“web.xml”文件,请运行该配置文件,否则,不要运行它。所以我试图避免对事物进行硬编码。这有意义吗?
    • 如果配置文件在父 POM 中并且所有子模块 POM 都继承自它,那么您应该能够使用 ${project.basedir}/src/main/webapp/WEB-INF/web.xml,因为 ${project.basedir} 是针对相应的子模块进行评估的。
    猜你喜欢
    • 2010-12-03
    • 2010-11-04
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 2011-04-01
    • 2019-04-18
    • 2013-09-24
    • 2011-11-12
    相关资源
    最近更新 更多