Main class not found, IntelliJ building a jar

sideways8 picture sideways8 · Jun 23, 2012 · Viewed 9.8k times · Source

I am running into problems when I try to run the jar file created in IntelliJ.
I followed the steps laid out here: How to build jars from IntelliJ properly? and searched far and wide for other people with the same problem using IntelliJ, and found no solution.
In the menu Project Structure>Artifacts section I have the package and main class name, and I have also tried specifying the 'Class path' bit using a relative and absolute path both to the source file and the .class file (which seems hidden in the IntelliJ Project display tree..), but even with all this (I also make sure to rebuild the jar every time I change something) I get the "Cannot find the main class. Program will exit." message when I try to run the jar.

In the main project folder, there is src and out.
out contains 'production' with the package tree and the class files
out also contains 'artifacts' with the jar folder and jar executable
src contains a folder of images, the META-INF and the package tree.
the first folder in the package contains the main class, so src/ravelDemo/RavelDemoMain.java

in Project Settings>Artifacts, the main class is listed as ravelDemo.RavelDemoMain
currently, the class path is out\production\RavelSequence v1.03\ravelDemo\ but this and every other class path I've specified (or left blank) doesn't seem to point to the right place. (RavelSequence v1.03 is the name of the project).

What am I doing wrong?

Answer

CrazyCoder picture CrazyCoder · Jun 24, 2012

Basing on the discussion is the comments above it appears that IntelliJ IDEA is building the valid executable jar with the main class correctly specified in the Manifest, this jar works fine when executed with java -jar ... command from the command line using the project target JDK version on the user's machine.

The problem is that it doesn't work on double click on @sideways8 system. It may be caused by the corrupted default Java installation or wrong .jar file type association in Windows registry. This is machine specific issue as I have no problem running the shared project jar on my system by double clicking on it.

To fix this problem you can try to uninstall all the Java versions present on this machine from the Control Panel | Programs and Features, then install new JDK from scratch so that it's the only JDK on the system and .jar file type is handled by it.

I use Total Commander which has a nice feature to check/edit file associations (File | Associate With...), here is how the .jar association is displayed when I press Edit type...:

jar file type