Avatar of Stian_B
Stian_B

asked on 

Jar file gives error message "Could not find the main class. Program will exit" on first try, works on second run

Hi all,

I've created a java application that should be deployed. However, on every deployment, when i first run the jar file, i get this error:

"Could not find the main class. Program will exit".

When i run the file again, it works, and it works every time after that..

I'm using netbeans, and the Main Class under project properties are set to "project".Main, which is the correct class. Does anyone have a suggestion?

stian
Editors IDEsJava

Avatar of undefined
Last Comment
CEHJ
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Make sure your manfest was written correctly in the jar
Avatar of Stian_B
Stian_B

ASKER

here is the content of manifest.mf

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.0-b16 (Sun Microsystems Inc.)
Main-Class: kassesystem.Main
Class-Path: lib/mysql-connector-java-5.1.6-bin.jar lib/RXTXcomm.jar li
 b/jsch-0.1.42.jar
X-COMMENT: Main-Class will be added automatically by build
Avatar of a_b
a_b

Do you  have the main-class attribute in the manifest file?

Also, have a look this link - http://forums.sun.com/thread.jspa?threadID=557868
Avatar of Stian_B
Stian_B

ASKER

The Main-Class looks right, and the strange thing is that the jar runs correctly on the second try, but fails every time on the first try..
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of a_b
a_b

Might be an eclipse issue as well. Are you running with the build automatically option checked?
Avatar of Stian_B
Stian_B

ASKER

CEHJ:

I'm not familiar with ant, how would i implement it? I'm kinda new to java, i've just learned it as problems came along with this project.

a_b:

i'm using netbeans.
Avatar of Stian_B
Stian_B

ASKER

i discoverd a strange thing.

When unpacking the jar file "kassesystem.jar", the classes are located in the unpacked folder kassesystem.
It seems to be many copies of every class. For example the main class has 5 classes:

Main$1.class  2 KB
Main$2.class  2 KB
Main$3.class  2KB
Main$4.class  2KB
Main.class  30 KB
Avatar of Stian_B
Stian_B

ASKER

"That suggests you have a task that depends on another one".

You're propably right, i'll install the program again and read the stack trace..
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Ant is used by Netbeans to implement its builds. If you're trying to run the thing through clicking then you need to make sure the main class is set for the project

>>It seems to be many copies of every class

Those are not copies, but inner classes
Avatar of Stian_B
Stian_B

ASKER

ah yes, you were right CEHJ, it was a dependency, when running the jar file i start mysqld, and then create tables the first time it's run, however, the service is not up and running yet, so there's the problem. Thanks
Avatar of Stian_B
Stian_B

ASKER

Thanks CEHJ, again:)
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

:-)

OK. Get to know ant by putting its bin directory on your PATH
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo