SpringBootDemo-0.0.1-SNAPSHOT.jar 中没有主清单属性

SpringBootDemo-0.0.1-SNAPSHOT.jar 中没有主清单属性

报错片段

下面展示一些 cmd代码片

shell 复制代码
D:\1sheji\1bisye\SpringBootDemo\target>java -jar SpringBootDemo-0.0.1-SNAPSHOT.jar
SpringBootDemo-0.0.1-SNAPSHOT.jar中没有主清单属性

问题原因

maven 在打包时没有配置主类。

我碰到的原因有 pom.xml 文件中没有配置,或者是配置参数错误。

解决方案

  1. 一般在选择并创建 SpringBoot 项目名时,pom 文件都会自动配置好主类。
  2. 但也有选择自己后续导入依赖配置 SpringBoot。

前者

xml 复制代码
<skip>true</skip>

将此行注释,或改为 false

xml 复制代码
<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.example.springbootdemo.SpringBootDemoApplication</mainClass>
           <!-- <skip>true</skip> -->
                </configuration>
<plugins>

原因:

这是一个 Java 项目的 Maven 配置文件 pom.xml 的一部分。 元素指定了项目的主类,也就是在执行项目时会调用的入口程序。在这个示例中,主类是 com.example.springbootdemo.SpringBootDemoApplication,也就是 Spring Boot 项目的启动类。

skip 元素设置为 true 时,Maven 会跳过这个项目的构建过程,也就是说项目不会被编译打包。这个设置通常在调试或测试阶段使用,可以避免重复构建和打包,加快开发速度。

后者:

在 pom.xml 中添加如下配置,会自动检测主类。

xml 复制代码
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

成功后

进入 jar 包所在文件夹,使用 cmd 命令(java -jar jar 包名 )再次运行后成功如图。

shell 复制代码
D:\1sheji\1bisye\SpringBootDemo\target>java -jar SpringBootDemo-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.6.13)

转载:SpringBootDemo-0.0.1-SNAPSHOT.jar中没有主清单属性

相关推荐
Dicky-_-zhang15 分钟前
系统容量规划与压测实战:从1万到100万QPS的科学扩容
java·jvm
Dicky-_-zhang6 小时前
消息队列Kafka/RocketMQ选型与高可用架构:从单体到100万TPS的演进
java·jvm
晨曦中的暮雨6 小时前
4.15腾讯 CSIG云服务产线 一面
java·开发语言
fake_ss1986 小时前
AI时代学习全栈项目开发的新范式
java·人工智能·学习·架构·个人开发·学习方法
茉莉玫瑰花茶6 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
未若君雅裁6 小时前
Spring AOP、日志切面与声明式事务原理
java·后端·spring
No8g攻城狮7 小时前
【人大金仓】wsl2+ubuntu22.04安装人大金仓数据库V9
java·数据库·spring boot·非关系型数据库
xiaoerbuyu12337 小时前
开源Java 邮箱 基于SpringBoot+Vue前后端分离的电子邮件
java·开发语言
C+++Python8 小时前
C++ 进阶学习完整指南
java·c++·学习