0

I have made jar file using netbeans, using Build and Clean Project Option. And I got .jar file ,now when i Execute it for a short period of time cmd window appears and gives a error as "Could not find or load main class while executing jar file "

Error That occured while executing

But if I execute jar using command prompt java -jar "C:\Users\varun\Documents\NetBeansProjects\StockRegister\dist\StockRegister.jar" It works fine

Output of Netbeans is :

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"

And in jar file ,I renamed it to .zip and opened it ,in Meta-Inf Folder of jar Manifest.MF says :

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

Does any one has any idea why this is happening.

1 Answer 1

1

You might have defined more than one class with main method. Use only 1 class with main method. Which would be your launcher class.(Will run first of all).

Sign up to request clarification or add additional context in comments.

3 Comments

You can have many classes, each having a main method. You specify which one to start with using Main-Class: MyPackage.MyClass in manifest.mf
@Marichyasana I have specified My main class, if I run through Jar by double clicking on it ,gives error while using cmd : java -jar pathtojar it works fine ,thats the issue i am facing
@Danish I have configured launching class via Manifest , and if that would be the case than , it won't run through calling jar file using cmd.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.