Error due to version compatibility in running jar file

I have created a jar file using JDK 8.0 and I tried to run the jar file in a system which is having JRE 7.0, but I am getting an error like this:

C:\Users\admin\Desktop>java -jar test.jar  
Exception in thread "main" java.lang.UnsupportedClassVersionError: test : Uns
upported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        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)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

What change am I need to make in my jar file creation. So that it will run without version compatibility?

Jon Skeet
people
quotationmark

You need to use the -source option for javac. For example:

javac -source 1.7 foo/Bar.java

In theory you can specify the source and target options separately, but judging by your comment, it sounds like you can't use Java 8 language features at all when targeting 1.7.

Note that this only covers your own source code. If xbasej-20091203.jar was built against Java 8, you'll need to find a version which targets Java 7 instead.

people

See more on this question at Stackoverflow