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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20697144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 03:38:40  来源:igfitidea点击:

Can not set the final jar name with maven-assembly-plugin

javamavenmaven-3

提问by Truong Ha

This is how I configured maven-assembly-plugin

我是这样配置的 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>

and I expect the final jar file should be myapp.jarbut it ends up with myapp-jar-with-dependencies.jar

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

Can you tell me how to configure to exclude "jar-with-dependencies"out of the final name?

你能告诉我如何配置以排除"jar-with-dependencies"最终名称吗?

采纳答案by sasankad

You can specify the finalNameproperty to give the jar the name you want, and specify that appendAssemblyIdshould be false to avoid the jar-with-dependenciessuffix. The configuration below will output a jar called test.jar

您可以指定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>