无法使用Maven-assembly-plugin设置最终的jar名称


76

这就是我的配置方式 maven-assembly-plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <finalName>myapp</finalName>
        <archive>
            <manifest>
                <mainClass>com.myapp.Main</mainClass>
            </manifest>
        </archive>
        <!--
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        -->
    </configuration>
</plugin>

我希望最终的jar文件应该是,myapp.jar但最终以myapp-jar-with-dependencies.jar

您能告诉我如何配置以排除"jar-with-dependencies"姓氏吗?

Answers:


188

您可以指定该finalName属性以为jar提供所需的名称,并指定该属性appendAssemblyId应为false以避免jar-with-dependencies后缀。下面的配置将输出一个名为test.jar

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <finalName>test</finalName>
                <archive>
                    <manifest>
                        <mainClass>com.myapp.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
               <appendAssemblyId>false</appendAssemblyId>
            </configuration>
         </plugin>

9
您也应该取消注释<descriptorRefs>,否则您将得到类似的信息: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:attached (default) on project ...: Error reading assemblies: No assembly descriptors found.
tsayen

5
优秀的<appendAssemblyId>false</appendAssemblyId>这条线是必须的。
GOXR3PLUS

标签“ finalName”不在程序集插件v3.x中
James Selvakumar,

2
但这会产生[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing
-isapir

@isapir,我在Google上搜索了一种解决方案,看来这可以按记录进行操作。参见issue.apache.org/jira/browse/MASSEMBLY-824。它还引用了maven.apache.org/plugins/maven-assembly-plugin/…,其中id字段显示设置此程序集的id。这是该项目中文件的特定程序集的符号名称。另外,除了用于通过将其值附加到生成的归档文件中来明确命名组装好的程序包之外,该ID还在部署时用作工件的分类器。我仍然不完全了解。
PatS
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.