Issue
I have a Spring Boot Application that is working.
I did
mvn clean package
and the .jar file is my target folder.
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...
Answered By - Per Huss
Answer Checked By - Gilberto Lyons (JavaFixing Admin)