• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

main class not found when launching jar

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???
1 Solution
I've seen this happen before. What happens when you do

java -jar yourjar.jar

at the command line?
schmidaAuthor Commented:
I tried it and found out that
java -jar myjar.jar
works on both systems.
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 ;-)
Independent Software Vendors: 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!

schmidaAuthor Commented:
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.
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
schmidaAuthor Commented:
thanks quddhus but everything was fine with my manifest the problem was with file associations.
>>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.
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Moderator

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now