I spent a few days learning java. Today I made a jar package and encountered a strange problem.
Java-jar test. Jar
You can run it correctly, but double-click it or run it in cmd, and the following error is prompted:
C: \ Users \ Administrator> D: \ work \ temp \ Classes \ test. Jar
Exception in thread "Main" Java. Lang. noclassdeffounderror: D: \ work \ temp \ Classes \
Test/jar
Caused by: Java. Lang. classnotfoundexception: D: \ work \ temp \ Classes \ test. Jar
At java.net. urlclassloader $ 1.run( unknown source)
At java. Security. accesscontroller. doprivileged (native method)
At java.net. urlclassloader. findclass (unknown source)
At java. Lang. classloader. loadclass (unknown source)
At sun. Misc. launcher $ appclassloader. loadclass (unknown source)
At java. Lang. classloader. loadclass (unknown source)
Cocould not find the main class: D: \ work \ temp \ Classes \ test. Jar. program will exit
Solution
Open the registry key, hkey_classes_root \ applications \ java.exe \ shell \ open \ command, and change the data to "C: \ Program Files \ Java \ jre6 \ bin \ java.exe "-jar" % 1 ", that is, the parameter-jar is added.
Or directly import the following registry files
Windows Registry Editor Version 5.00
[Hkey_classes_root \ applications \ java.exe \ shell \ open \ command]
@ = "\" C :\\ Program Files \ Java \ jre6 \ bin \ java.exe \ "-jar \" % 1 \""
Note:
If you double-click to open the jar package and use javaw, You need to modify the corresponding Registry Key of javaw.
The differences between Java and javaw are as follows:
Java is compiled based on plain text. If it is graphical, it can be printed as plain text at any time in Java. If you are checking for errors, use Java. If the program is purely graphical and you need to increase the speed, use javaw.