执行jar文件时无法找到或加载主类

时间:2015-11-15 09:33:19

标签: java jar

我使用netbeans制作了jar文件,使用Build and Clean Project Option。 我得到.jar文件,现在当我执行它很短的时间cmd窗口出现并给出一个错误“执行jar文件时无法找到或加载主类”

Error That occured while executing

但是如果我使用命令提示符java -jar "C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist\StockRegister.jar"执行jar 它工作正常

Netbeans的输出是:

Updating property file: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\built-clean.properties
Deleting directory C:\Users\varun\Documents\NetBeansProjects\StockRegister\build
clean:
init:
deps-jar:
Created dir: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build
Updating property file: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\built-jar.properties
Created dir: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\classes
Created dir: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\empty
Created dir: C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\generated-sources\ap-source-output
Compiling 8 source files to C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\classes
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\varun\Documents\NetBeansProjects\StockRegister\src\stockregister\EnterPurchase.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Copying 17 files to C:\Users\varun\Documents\NetBeansProjects\StockRegister\build\classes
compile:
Created dir: C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist
Copying 1 file to C:\Users\varun\Documents\NetBeansProjects\StockRegister\build
Copy libraries to C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist\lib.
Building jar: C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist\StockRegister.jar
To run this application from the command line without Ant, try:
java -jar "C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist\StockRegister.jar"

在jar文件中,我将其重命名为.zip并在jar的Meta-Inf文件夹中打开它 Manifest.MF说:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.7.0_25-b16 (Oracle Corporation)
Class-Path: lib/AbsoluteLayout.jar lib/mysql-connector-java-5.0.8-bin.
 jar lib/swingx-all-1.6.4.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: stockregister.StockRegister

有没有人知道为什么会这样。

1 个答案:

答案 0 :(得分:1)

您可能已使用方法定义了多个类。 使用只有1个主要方法。 这将是你的发射器类。(将首先运行)。