I have a Spring Boot application that builds a jar successfully. However, when I run this jar, I receive an error:
mvn clean install
> java -jar target/my-app-api-0.0.local.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
However, I am able to run the app through the spring-boot-maven-plugin
via IntelliJ maven tab or through the mvn spring-boot:run command
. The plugin is included in the pom:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
What could be a reason for this difference? I had previously received an error for not having a main
method declared in the generated manifest, but added the maven-jar-plugin to specify this
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.proofpoint.app.MyAppApiApplication
Spring-Boot-Version: 3.0.2
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Classpath-Index: BOOT-INF/classpath.idx
Spring-Boot-Layers-Index: BOOT-INF/layers.idx
I'm guessing you didn't add the dependency to your POM, although I can't know without seeing it.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>3.0.2</version>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.