【Maven】maven打包生成可执行jar文件

2022-09-01 16:05:51 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

maven默认打包生成的jar是不能够直接运行的,因为在jar文件的META-INF/MANIFEST.MF文中没有Main-Class一行,为了生成可执行的jar文件,需要借助maven的插件,maven-shade-plugin,配置该插件如下:

代码语言:javascript复制
<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>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/141781.html原文链接:https://javaforall.cn

0 人点赞