MAVEN打包JAR启动执行manifest

当您使用Maven进行项目打包,特别是需要创建一个可执行的JAR文件时,确保JAR文件的MANIFEST.MF中包含正确的Main-Class属性是非常重要的。这个属性告诉Java运行时环境哪个类包含main方法,作为应用程序的入口点。

如果您发现生成的JAR文件不包含Main-Class属性,您可以在maven-assembly-plugin插件的配置中指定它。以下是如何在Maven的pom.xml文件中配置maven-assembly-plugin以包含Main-Class属性的示例:

XML 复制代码
<plugin>
    <artifactId>maven-assembly-plugin </artifactId>
    <configuration>
        <descriptorRefs>
            <!-- 此处填写打包后jar包后添加的标识 -->
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <!-- 此处填写程序的主入口(main方法) -->
                <mainClass>com.example.demo.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
相关推荐
Macbethad1 小时前
自动化测试技术报告
开发语言·lua
不会画画的画师1 小时前
Go开发指南:io/ioutil包应用和迁移指南
开发语言·后端·golang
2503_928411561 小时前
12.22 wxml语法
开发语言·前端·javascript
AM越.1 小时前
Java设计模式详解--装饰器设计模式(含uml图)
java·设计模式·uml
5980354151 小时前
【java工具类】小数、整数转中文大写
android·java·开发语言
JIngJaneIL1 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
吃喝不愁霸王餐APP开发者2 小时前
Java后端服务在对接全国性霸王餐API时的多数据中心部署与就近调用策略
java·开发语言
从心归零2 小时前
springboot-jpa的批量更新方法
java·spring boot·spring
froginwe112 小时前
jQuery UI 实例
开发语言
这周也會开心2 小时前
128陷阱,==与equals区别
java·开发语言