4

I'm trying to deploy Spring Boot application. I build a jar file through maven plugins. But I get an error saying:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication at com.spring-boot.example.AppConfig.main(AppConfig.java:18) Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more 

I tried adding additional plugins to the pom.xml file, but none of it worked. Any help will be very appreciated.

This is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.spring-boot.example</groupId> <artifactId>spring-boot-example</artifactId> <version>0.1</version> <properties> <java.version>1.8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <start-class>com.spring-boot.example.AppConfig</start-class> <spring.version>4.0.7.RELEASE</spring.version> <log4j.version>1.2.17</log4j.version> <jdk.version>1.7</jdk.version> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.2.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> <version>1.2.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 
2
  • How are you building, deploying and running your application? The error means you are missing Spring jar files on the classpath. Commented Oct 16, 2015 at 9:09
  • I run it by clinking Plugins -> spring-boot:run-> "Run Maven Build". I deploy it by clicking Plugins -> jar:jar -> "Run Maven Build". Commented Oct 19, 2015 at 10:28

3 Answers 3

3

First of all I would suggest you to upgrade your dependecies to the latest version of the Spring Boot framework, if applicable.

Besides, independently from the version you're using, the class you're missing is contained into this dependency:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>1.2.6.RELEASE</version> </dependency> 

but remember that all Spring Boot dependencies rely on Spring framework transitive dependencies, so check in your IDE's dependency hierarchy panel if they are present.

Depending on the way you're deploying your application you must be sure that all dependencies are available at runtime.

This can be obtained using, for example, the repackage goal into the spring-boot-maven-plugin in your pom's build section:

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring-boot-version}</version> <configuration> <mainClass>your-main-class</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 
Sign up to request clarification or add additional context in comments.

2 Comments

I can't change the version, I get errors. I did change the plugin, but the result is the same as before (I get an exception java.lang.NoClassDefFoundError).
Ok, I solved it. For people with the same problem: stackoverflow.com/questions/23868580/…
0

I would suggest using maven assembly plugin so that all dependencies will be present in jar file after it is built. Here is documentation for it: http://maven.apache.org/plugins/maven-assembly-plugin/

Comments

-1

try $ mvn dependency:purge-local-repository from your terminal. It may be because some of your dependency got corrupted. This command worked for me

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.