An error occurred while running the jar package.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.