Solved

main class not found when launching jar

Posted on 2004-08-11
9
243 Views
Last Modified: 2012-06-22
I ran into a strange problem while trying to deliever a java application. I stored all my application into a jar and added a correct manifest file (created with eclipse). When I try to start the application with a double click everything works fine on my system, the application is launched as expected. The problem is when I copy the jar file ( it is really exactly the same jar) to another system and try to launch it with a double click I get the error: "Could not find the main class. Program will exit.". The file type jar is associated with javaw and java is properly installed on both systems. Has anybody an idea why the same jar file migth launch on one system but fail to find the main class on another???
0
Comment
Question by:schmida
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11774777
I've seen this happen before. What happens when you do

java -jar yourjar.jar

at the command line?
0
 
LVL 1

Author Comment

by:schmida
ID: 11774918
I tried it and found out that
java -jar myjar.jar
works on both systems.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11774965
I don't know the reason for the problem, but a good workaround is to use precisely that command as the command for a shortcut. You can even use your own icon ;-)
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Author Comment

by:schmida
ID: 11775294
Ok I fixed the problem. The problem was that the jarfile was launched with javaw - jar on one system and only with javaw on the other. When java is installed it puts a registry key name jarfile into HKEY_CLASSES_ROOT which specifies that jar files have to be opened with the command javaw -jar. The ending .jar (also in HKEY_CLASSES_ROOT) is then associated with the jarfile entry. When Winrar is installed on the system it chnges the association of .jar with jarfile to WinRAR. If try to associate jar files with javaw again the files are only open with javaw. To fix the problem the value of the .jar entry in HKEY_CLASSES_ROOT has to be reset to jarfile. Thanx for trying to help me CEHJ anyway. I ll ask to refund the points.
0
 
LVL 1

Expert Comment

by:quddhus
ID: 11775327
make sure that the manifest file has this entry :- also make sure java bin folder is in PATH.

Manifest-Version: 1.0
Created-By: ABC
Main-Class: MyMainclass
0
 
LVL 1

Author Comment

by:schmida
ID: 11775390
thanks quddhus but everything was fine with my manifest the problem was with file associations.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11775495
>>When Winrar is installed on the system it chnges the association of .jar with jarfile to WinRAR.

That's the kind of bad behaviour you don't need ;-)

>>I ll ask to refund the points.

That's OK.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 11811613
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Moderator
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java SE 8u111  Lot of stuff broke 11 69
Should localization be done inside spring controller 5 25
difference of if loops 23 49
servlet example 11 40
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question