【问题标题】:Forcing maven assembly plugin to run after maven profile changed properties在 maven 配置文件更改属性后强制 maven 程序集插件运行
【发布时间】:2013-01-15 14:47:31
【问题描述】:

我正在使用带有配置文件的 maven 程序集插件来生成具有应用程序结构的 zip 文件并保证路径正确:

<profiles>
    <profile>
        <id>desenvolvimento</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <arquivo_tef4j>classpath:tef4j.properties</arquivo_tef4j>
            <arquivo_bd>classpath:bancoDados.properties</arquivo_bd>
            <arquivo_aplicacao>classpath:aplicacao.properties</arquivo_aplicacao>
            <modelo_dav>classpath:modelos_relatorio/dav.rptdesign</modelo_dav>
        </properties>
    </profile>
    <profile>
        <id>producao</id>
        <properties>
            <arquivo_tef4j>file:../config/tef4j.properties</arquivo_tef4j>
            <arquivo_bd>file:../config/bancoDados.properties</arquivo_bd>
            <arquivo_aplicacao>file:../config/aplicacao.properties</arquivo_aplicacao>
            <modelo_dav>file:../modelos/dav.rptdesign</modelo_dav>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <finalName>${project.artifactId}</finalName>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>../lib/</classpathPrefix>
                                <mainClass>com.hrgi.pdv.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/assembly.xml</descriptor>
                        </descriptors>
                        <archive>
                            <manifest>
                                <mainClass>com.hrgi.pdv.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

名为“desenvolvimento”的配置文件用于与 IDE 一起开发,另一个配置文件用于生成生产的 zip 文件。如您所见,配置文件的差异基本上在于属性值。当我使用“desenvolvimento”配置文件时,它们运行良好,但是第二个配置文件中的属性“modelo_dav”有一些问题。 该属性在“aplicacao.properties”中使用,但程序集插件复制“aplicacao.properties”而不更改属性$ {modelo_dav},如果我打开jar文件“aplicacao.properties”文件具有正确的值,所以我'我假设程序集插件在 maven 更改属性之前复制文件。 maven更改属性后,有没有办法强制程序集插件复制文件?另一个问题是:如何从最终的 jar 文件中删除属性文件?

【问题讨论】:

    标签: maven maven-plugin maven-assembly-plugin maven-profiles


    【解决方案1】:

    您的程序集在与 jar 相同的package 阶段运行,并且在处理过滤的process-resources 阶段之后,至少在默认情况下是这样。因此,这表明这不是排序问题。

    我建议您仔细检查并进行某种测试,以确定程序集从何处获取文件。它可能是直接从未处理的源端获取一个,而不是目标。

    【讨论】:

      【解决方案2】:

      你可以做的是让程序集插件从构建目录而不是源目录复制资源文件,如下: 改变

      <fileSet>
        <directory>${project.basedir}/src/main/resources</directory>
        <outputDirectory>conf</outputDirectory>
        <includes>
          <include>*.properties</include>
        </includes>
      </fileSet>

      进入

      <fileSet>
        <directory>${project.build.directory}/classes</directory>
        <outputDirectory>conf</outputDirectory>
        <includes>
          <include>*.properties</include>
        </includes>
      </fileSet>

      【讨论】:

        猜你喜欢
        • 2017-01-28
        • 1970-01-01
        • 2012-12-30
        • 2020-06-03
        • 1970-01-01
        • 1970-01-01
        • 2010-11-07
        • 2020-01-02
        • 1970-01-01
        相关资源
        最近更新 更多