Error ClassNotFoundException in jar file Maven Java app

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Error ClassNotFoundException in jar file Maven Java app



I'm having an error when I try to package my app. It works perfectly if a run the app without packaging. I read lot of posts having the same problem but any solution is working for me. I'm trying to upload my server-side app into the server.



I'm a bit new in java spring boot.



The pom.xml is


<?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>GastosApp</groupId>
<artifactId>GastosApp</artifactId>
<version>1.0-SNAPSHOT</version>


<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<start-class>Gastos.Application</start-class>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.mobile</groupId>
<artifactId>spring-mobile-device</artifactId>
<version>1.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<mainClass>Gastos.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Gastos.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>



I read that the problem could be in my main Class, because is an implementation of the CommandLineRunner interface. But I need that.



Any suggestion?



Thanks all.



EDDITED



The Main Class:


@SpringBootApplication
public class Application implements CommandLineRunner
@Autowired
private UserRepository repository;

public static void main(String args)
SpringApplication.run(Application.class, args);


@Override
public void run(String... args) throws Exception
System.out.println("Users found with findAll():");
System.out.println("-------------------------------");
for (User user : repository.findAll())
System.out.println(user);

System.out.println();






First hint never mix versions of spring-boot parts...cause your parent has 2.0.3.RELEASE where as your spring-boot-starter-security has 2.0.4.RELEASE...furthermore why are you defining persistence-api with a version? Is defined by the spring-boot parent...(If I correctly remember)...Apart from that why are you using maven-assembly-plugin? The spring-boot-maven-plugin will handle that...BTW: Without the code of your main class it's really hard to say something ?...
– khmarbaise
Aug 10 at 10:03





Which class is not Found?
– xyz
Aug 10 at 10:04





@xyz Main Class
– Ary
Aug 10 at 10:51





could you please add some stacktrace
– xyz
Aug 10 at 12:37





@khmarbaise ok I added the main Class.
– Ary
Aug 10 at 13:47




2 Answers
2



You should not package Springboot application by yourself. Springboot provided a Maven plugin for package. See here



Create new class which will implement the CommandLineRunner and mark this class as a component.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS