Monday, April 25, 2022

maven: Caused by: java.lang.ClassNotFoundException: com.drillback.sgsup.Application

>PROBLEM


Running the executable jar with dependencies generated by maven plugin fails throwing the error message:

  java -jar myApp-0.0.1-SNAPSHOT-jar-with-dependencies.jar


- Returns:

  ..Caused by: java.lang.ClassNotFoundException..



>SOLUTION


1. Check the main class path in the pom.xml file.

Note: there are alternative plugins to generate executable jars.

See more at: 
How to Create an Executable JAR with Maven


Below is shown one of the options:


<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>package.appName.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>



2. If the plugins's configuration is correct, check the dependencies included in the project's pom.
For instance, if it was included lombok as shown below, remove it and test again:

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>



>ENV


java
spring
maven

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...