Exception in thread “main” java.lang.NullPointerException : While trying to the run the jar file

Deadly 提交于 2019-12-24 02:44:09

问题


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 :

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


回答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:


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

Main-Class: com.Main


来源:https://stackoverflow.com/questions/9287997/exception-in-thread-main-java-lang-nullpointerexception-while-trying-to-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!