Java compilation and running error: Java. Lang. unsupportedclassversionerror: bad version n umber in. Class File

Source: Internet
Author: User

Here we use

Http://blog.csdn.net/oscar999/article/details/7305489

Jdbctest. Java source file in

1. Use the compilation command in JDK to compile the. Class file.

"C:\Program Files\Java\jdk1.6.0_24\bin\javac.exe" -cp ojdbc14.jar; JDBCTest.java

2. Run the Java command in jdk1.5.

"C:\Program Files\Java\jdk1.5.0_14\bin\java.exe" -cp ojdbc14.jar; JDBCTest

The following error occurs,

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file        at java.lang.ClassLoader.defineClass1(Native Method)        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)        at java.security.AccessController.doPrivileged(Native Method)        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

It seems that Java cannot be compiled in a later version.

On the contrary, if you compile in a lower version, can you run it in a later version?

After testing, you can.

Add javac and Java import lib

Sometimes in order to test something, we use javac and Java commands to compile and run the test class we temporarily wrote. What if other jar packages are used for this test class? We can use the-classpath or-CP parameter to import these required packages.
Assume that the test Class F: \ test. Java is used, and the Lib used is c: \ ABC. jar and D: \ EFG. Jar respectively. So we can write the compilation and running commands in this way.
Javac-CP c: \ ABC. jar; D: \ EFG. jar; F: \ test. Java
Java-CP c: \ ABC. jar; D: \ EFG. jar; F: \ test
Note: The last one. The class and Lib package must be separated by spaces. If it is in Linux, replace; with: the path must also be replaced with the Linux format.

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.