Search code examples
javajar

JAR: Could not find the main class


It is a typical error message, yet no search result could help me. I am trying to build & run a java tool someone coded.

I get the following error:

Could not find the main class: ConnJKSEngine.  Program will exit.

Here is my manifest:

Main-Class: ConnJKSEngine

I also changed this to

Main-Class: ConnJKSEngine.ConnJKSEngine

and

Main-Class: ConnJKSEngine/ConnJKSEngine

(it has a newline at the end). Did not make any difference

This is how I build the jar:

javac -cp ConnJKSEngine/ ConnJKSEngine/ConnJKSEngine.java
jar -cvfm ConnJKSEngine.jar ConnJKSEngine/ConnJKSEngineManifest ConnJKSEngine/*.class
chmod +x ConnJKSEngine.jar

This is how I try to run the jar (tried all of them):

java ConnJKSEngine.jar
java -jar ConnJKSEngine.jar
java -cp ConnJKSEngine.jar ConnJKSEngine

This is the table of contents as given by jar -tf ConnJKSEngine.jar

META-INF/
META-INF/MANIFEST.MF
ConnJKSEngine/ConnJKSEngine.class
ConnJKSEngine/ConnJKSEngine_GenKey.class
ConnJKSEngine/ConnJKSEngine_GetPubKey.class
ConnJKSEngine/ConnJKSEngine_Operation.class
ConnJKSEngine/ConnJKSEngine_PrivDec.class
ConnJKSEngine/ConnJKSEngine_Sign.class

I've changed to the ConnJKSEngine directory and executed java ConnJKSEngine, it correctly prints usage information. This makes me sure that the main class exists and can be executed. So something must be wrong with building the jar, right?

So I went ahead and unpacked the jar to a different directory (unzip ConnJKSEngine.zip) and got the directory structure shown above. If I head into ConnJKSEngine directory and execute java ConnJKSEngine, it executes correctly.

Here I am stuck: The class is in there, it is in the subdirectory and it can be executed. The manifest seems to be correct. Since I am not a java programmer, I come here now. Any idea what could be going on? (note: Linux system)

Edit The sources can be found here: https://github.com/Javex/JKSEngine


Solution

  • I think that your main class should have fully qualified name ConnJKSEngine.ConnJKSEngine or your jar content should look like this:

    META-INF/
    META-INF/MANIFEST.MF
    ConnJKSEngine.class
    ConnJKSEngine_GenKey.class
    ConnJKSEngine_GetPubKey.class
    ConnJKSEngine_Operation.class
    ConnJKSEngine_PrivDec.class
    ConnJKSEngine_Sign.class