简体   繁体   English

无法运行jar文件

[英]Unable to run jar file

MANIFEST.MF 清单文件

Manifest-Version: 1.0  
Created-By: 1.7.0_01 (Oracle Corporation)  
Main-Class: useDisplay

NOTE: There is a blank line after the Main-Class 注意:Main-Class之后有一个空白行

display.java display.java

public class display  
{  
    public void displayText()
    {
       System.out.println ("In displayText");
    }
}

useDisplay.java useDisplay.java

public class useDisplay  
{
   public static void main (String args[])  
   {
      System.out.println ("In displayText");
   }
}

I ran the following commands: 我运行了以下命令:

javac *java
jar cf my1.jar MANIFEST.MF *class  
java -jar my1.jar  

I got the following errors: 我收到以下错误:

Exception in thread "main" java.lang.NullPointerException at 
sun.launcher.LauncherHelper.getMainClassFromJar(LauncherHelper.java:399) 

at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:463)

This should be a very simple example. 这应该是一个非常简单的示例。 The program works without the jar file. 该程序无需jar文件即可工作。 I have no idea what it's complaining about. 我不知道它在抱怨什么。

我相信您必须在jar命令中添加-m才能使用您指定的MANIFEST.MF文件

jar cfm my1.jar MANIFEST.MF *class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM