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:
Main class and file structure:
This run config works perfectly fine in intellij
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:
- https://stackoverflow.com/a/42200519/104891
- https://youtrack.jetbrains.com/issue/IDEA-116209#comment=27-656589
- https://stackoverflow.com/a/45169655/104891
- https://stackoverflow.com/a/42660624/104891
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.