sweets_wn的gravatar头像
sweets_wn 2018-09-12 14:55:40
问题集锦(二)__maven项目打jar包找不到主清单属性

环境

Intellij IDEA

Maven3

问题描述

用maven进行引入jar包管理的项目,打jar包后,命令行执行:java - jar XXX.jar,启动失败,错误信息为:XXX.jar中没有主清单属性。根据提示,显然是MANIFEST.MF文件中的Main-Class(主函数入口)属性问题,rar方式打开jar包,打开MANIFEST.MF文件,里面没有找到Main-Class的配置。

解决方案

1. 修改pom.xml

增加如下插件:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>timer.ScheduleManager</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

其中问题集锦(二)__maven项目打jar包找不到主清单属性修改为对应的主函数。

2. 重新打包。maven clean-->maven install

问题集锦(二)__maven项目打jar包找不到主清单属性

3. 查看重新打的jar包

问题集锦(二)__maven项目打jar包找不到主清单属性

4. 运行jar包

java -jar XXX.jar

问题解决。


打赏
最近浏览
zjq5204  LV2 2021年9月27日
971695556qwe  LV7 2021年5月20日
topone2018  LV1 2020年9月2日
1587039373  LV3 2020年6月18日
wo2184245  LV3 2020年1月3日
huangdong3100  LV2 2019年12月30日
shijchen  LV2 2019年12月30日
linkadsf 2019年12月17日
暂无贡献等级
tyjava 2019年11月30日
暂无贡献等级
xp95323  LV15 2019年10月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友