java - 在 assembly-plugin 构建(具有依赖性)jar 中包含 Maven 配置文件名称

标签 java maven-3 maven-assembly-plugin

我正在使用 maven-assembly-plugin 构建一个可执行的、具有依赖项的整体 jar。我还使用资源过滤来设置一些自定义的、 channel 特定的(dev、stage、prod 等)属性。

如何使 jar 的最终名称包含 channel 名称(dev、stage、prod 等)?

我想要以下 mvn 命令生成如下所示的 jar:

  • mvn clean install -P DEV --> ws-client-DEV.jar
  • mvn clean install -P STAGE --> ws-client-STAGE.jar
  • mvn clean install -P PROD --> ws-client-PROD.jar

有没有我找不到的 Maven 属性?如果可能,我想避免使用冗余命令行参数(即 - 'mvn clean install -P DEV -Dlane=DEV')。

这是我的程序集插件配置:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.2</version>
    <executions>
        <execution>
            <id>jar-with-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <finalName>ws-client</finalName>
        <appendAssemblyId>false</appendAssemblyId>
        <archive>
            <manifest>
                <mainClass>Example</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

最佳答案

与 Bhaskar 的类似,但略有修改。

标签后加入

<finalName>${project.artifactId}-${lane}</finalName>

您可以将车道值设置为配置文件中的属性。

<profiles>
    <profile>
        <id>DEV</id>
        <properties>
            <lane>DEV</lane>
        </properties>
    </profile>
</profiles>

然后像你说的那样执行构建: mvn ... -P DEV(例如 mvn clean install -P DEV)

关于java - 在 assembly-plugin 构建(具有依赖性)jar 中包含 Maven 配置文件名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10400886/

相关文章:

java - 面临异常 : org. openqa.selenium.NoSuchSessionException : A session is either terminated or not started site:stackoverflow. com

build - Maven Checkstyle 插件创建空报告

java - Maven:构建可运行的 jar,然后使用 maven-assembly-plugin 添加到 zip

java - 将家长文档包含到 zip 文件中

Java 8 stream partitioningBy 假条件下的第二个谓词

java - selenium - 需要从动态加载的分区中找到一个元素并单击它

java - Bean 配置 xml 文件头错误 -

Maven 原型(prototype) keepParent 选项的作用是什么

eclipse - 在 Eclipse IDE 上使用 Maven 3 创建基于 Java EE 6 的 Web 服务

java - Maven 程序集 : add different version of the same artifact