Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Spring Boot JAR file not working with ClassNotFoundException

I have a Spring Boot Application that is working.

I did

mvn clean package

and the .jar file is my target folder.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Then I try to execute the following command:

java -jar .\target\my-application-0.0.1-SNAPSHOT.jar

and I get the following Error:

Exception in thread "main" java.lang.ClassNotFoundException: C:\Users\test\example-application\example-app/src/main/test/ExampleApplication
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:467)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)

Researching on stackoverflow just recommend an issue that I already included …
It was recommended to include this plugin in order to include the maven jars into the project …. spring-boot-maven-plugin

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

What else could be the reason for it not working?

>Solution :

The class name in the exception is a file name and not a class name. That makes me suspect that you have specified the main class incorrectly. Have you specified the name of the class in the spring-boot-maven-plugin with

<configuration>
  <mainClass>foo.bar.ExampleApplication</mainClass>
</configuration>

or as a Main-Class in the manifest? Note that you should use dot notation for packages…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading