Solved

main class not found when launching jar

Posted on 2004-08-11
9
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

726 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