您的位置:首页 > 其它

maven打包生成可执行jar文件

2017-10-12 16:48 465 查看

maven打包生成可执行jar文件

maven默认打包生成的jar是不能够直接运行的,因为在jar文件的
META-INF/MANIFEST.MF文中没有Main-Class
一行.

为了生成可执行的jar文件,需要借助maven的插件,
maven-shade-plugin
.

配置该插件如下:

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<exec.mainClass>study20161230.Test</exec.mainClass>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${exec.mainClass}</mainClass>
</transformer>
</transformers>
<artifactSet>
</artifactSet>
<!--<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>-->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息