尝试运行jar文件时

尝试运行jar文件时

本文介绍了线程“主”中的异常java.lang.NullPointerException:尝试运行jar文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行命令 java -jar MyJar.jar 我得到以下错误:

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 ?

在我将包装在jar文件中之前,场景是:

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

注意:当我解压缩jar文件时,有一个名为 META-INF 的文件夹还包含 MANIFEST.MF ,但不包含主类的名称。

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.

我的清单的内容。 MF:主类:messenger.Messenger 也尝试通过放斜杠

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

推荐答案

添加jar不足以将其包含在文件中,您需要我们e m 选项,如

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

根据。选项 m f 的顺序必须匹配<$ c的名称的参数顺序$ c> MANIFEST 文件和jar文件。

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.

也考虑到这个警告:现有的清单文件必须以新行字符。如果不以新的行字符结尾,则jar不解析清单文件的最后一行。

这篇关于线程“主”中的异常java.lang.NullPointerException:尝试运行jar文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:22