Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javapackager: Cannot find or load main class

Tags:

java

I have created a JavaFX project and am able to run it with the command

java -classpath [very-long-list-of-class-paths] danIDE.Main

However, when I try to use javapackager to create a jar out of it and run with java -jar out.jar, the prompt says Error: Could not find or load main class danIDE.Main

The command I used to create the jar is

javapackager -createjar -v -classpath [very-long-list-of-class-paths] -srcdir src -outfile out -appclass danIDE.Main

I have googled for a long time on this problem and I still couldn't find the solution. Can someone point me to the right direction? Thanks a lot!


Edit: Here is the project structure.

Project Structure

and here is the exploded jar.

enter image description here

New exploded jar as @Garry requested:

enter image description here

like image 913
Tengyu Liu Avatar asked Jul 27 '15 04:07

Tengyu Liu


2 Answers

Since you're using IntelliJ IDEA I suggest you let IDEA create your JAR file for you.

First, open up the module settings window:

enter image description here

Then, add a new artifact:

enter image description here

Select JAR From modules with dependencies:

enter image description here

Select your main class in the window and decide if you want to repackage all classes from your dependency JARs in your JAR (extract to target JAR option) or if you want to distribute them alongside your JAR (copy to the output directory and link via manifest option):

enter image description here

If you want to build it whenever you build the project (probably a good idea), click the checkbox for that:

enter image description here

When you next Make the project, the JAR will show up under out/artifacts:

enter image description here

If you didn't click the checkbox for building the JAR when you build the project you can build the JAR from the Build Artifacts option in the Build menu.

like image 138
Raniz Avatar answered Sep 30 '22 12:09

Raniz


Can you try using below command? Make sure to update 'classes' folder to the Base directory of the files to package.

As you said in question that you are able to run danIDE.Main so I assume all the required classes are available in dist folder. So create a folder out in the project parallel to dist

javapackager -createjar -classpath [very-long-list-of-class-paths] -appclass danIDE.Main -srcdir dist -outdir out -outfile out.jar -v 

Updated: as per the uploaded screenshot: point -srcdir to dist, now the generated jar out.jar will be placed in out/out.jar

like image 43
Garry Avatar answered Sep 30 '22 14:09

Garry