Why is my fat JAR not running on different PCs - main class not found?

Albert Hattingh :

I built a javaFX artifact using IntelliJ. My first problem was in the Application Class box, where it didn't automatically detect my main class, or even suggest any classes as main class when I searched in the search box. I saw that it was a bug with IntelliJ, somewhere on StackOverflow, and I just manually entered my packageName.Main in the application class box.

I have two dependencies that I extracted into this output root. The output of building the artifact looks like this.

Then after rebuilding the project the JAR runs on my PC 100%, even if I move the JAR to another directory, it works 100%.

So I copied this JAR (Swansong.jar) to my other PC and when I double-clicked it, nothing happended. When I ran it in the cmd: java -jar Swansong.jar I got this error:

Error: Could not find or load main class swansong.Main
Caused by: java.lang.ClassNotFoundException: swansong.Main

I read about manifest files but I can't find a manifest file anywhere in my project, but if I extract the JAR file the manifest file that was generated looks like this. Can anyone please help me, why does the JAR run on one PC but not on the other? And how can I fix this?

UPDATE: This is the contents of my jar file and this is the contents of the swansong directory inside the jar file.

UPDATE 2: I feel stupid. My main PC runs jdk8 and my other pc runs jdk11. And JavaFX is not included in the jdk11. So I think this is the problem, but not 100% sure yet. Will test and see. Are there any workarounds for this?

Albert Hattingh :

I hate to admit it, but the solution to the problem was staring me in the face all along, and I am truly embarrassed. I used Java 8 to develop the program. Target PC was using Java 11 and I never thought to check the JDK version, because I thought I was using JDK8 on both PCs.

JavaFX is included in JDK8, but not in JDK11. It should be added to a project as an external library when using newer JDK versions. I just used JDK8 for running the program and everything works 100%. Thanks for the answers and comments though, I learned a lot about manifests and classpaths trying to solve this problem, so the effort was not in vain!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324292&siteId=1