2

When i run the command java -jar MyJar.jar i get the following errors :

Exception in thread "main" java.lang.NullPointerException
    at sun.launcher.LauncherHelper.getMainClassFromJar(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

What errors are these ? What could be the reason i am getting these errors ?

Before I packed the packages in a jar file the scene was :

enter image description here

Then i packed the above files along with the packages by entering :

jar -cf MyJar.jar .\Design\*.class .\InterfaceImplementation\*.class .\Interfaces\*.class .\messenger\*.class Manifest.MF RemoteMethodImpl_Stub.class

NOTE : When i unpack the jar file there is a folder named META-INF which also contains MANIFEST.MF but not the name of main class.

The content of my MANIFEST.MF : Main-Class : messenger.Messenger also tried by putting a forward slash

3
  • 2
    To be clear, what was the content of your MANIFEST.MF?
    – madth3
    Feb 15, 2012 at 4:48
  • @ madth3 Main-Class : messenger/Messenger Here messenger is the directory and Messenger is the name of main class Feb 15, 2012 at 4:53
  • I guess, it should be fully qualified name of class.
    – Azodious
    Feb 15, 2012 at 5:23

2 Answers 2

1

To add the jar is not enough to include it in the files, you have to use the m option, like

jar cmf myManifestFile myFile.jar *.class

according to jar documentation. The order of the options m and f has to match the order of the parameters for the name of the MANIFEST file and the jar file.

Take into account this warning too: An existing manifest file must end with a new line character. jar does not parse the last line of a manifest file if it does not end with a new line character.

2
  • Then i get the following exceptions : java.io.FileNotFoundException: MyJar.jar (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:137) at java.io.FileInputStream.<init>(FileInputStream.java:96) at sun.tools.jar.Main.run(Main.java:170) at sun.tools.jar.Main.main(Main.java:1176) Feb 15, 2012 at 5:11
  • When do you get the error? At creating the jar or at executing? If it's the first, you have to follow the order of the options and the parameters. If it's the later, have you verified the MANIFEST.MF inside the jar is correct now?
    – madth3
    Feb 15, 2012 at 6:03
1

The error is obviously due to missing main class in manifest...you can specify main class in manifest like this

Main-Class: com.Main

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.