Link to home
Start Free TrialLog in
Avatar of schmida
schmida

asked on

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???
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

I've seen this happen before. What happens when you do

java -jar yourjar.jar

at the command line?
Avatar of schmida
schmida

ASKER

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 ;-)
Avatar of schmida

ASKER

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
Avatar of schmida

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial