Home > database >  Java Could not find or load main class when running jar file
Java Could not find or load main class when running jar file

Time:11-30

I have a springboot application, it runs just fine in intellij. I'm trying to create an executable jar to run the application on other machines. I followed this

tutorialhttps://www.jetbrains.com/idea/guide/tutorials/hello-world/packaging-the-application/

down to every step, and managed to build my jar. but when i try to run the jar with

java -jar nameofjar.java

I get a Could not find or load main class error. I unzipped the jar file with java c and the classpath correctly points to the main class, so im really lost as to what i have to fix here to get java to detect the main class.

I've tried a bunch of solutions from here:

enter image description here

Main class and file structure: main class

This run config works perfectly fine in intellij enter image description here

here is my manifest.mf:

Manifest-Version: 1.0
Main-Class: com.owl.PosApi.OwlPosApiApplication

CodePudding user response:

If you build jar artifact using IntelliJ IDEA, it may be incomplete or manifests from the other included dependencies can override your custom one with the main class defined.

Related answers:

The proper solution would be to build the artifact using Maven. It may work out of the box with mvn clean package or you may need to modify pom.xml to build the fat jar with all the dependencies per this document.

  • Related