0

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.access100ドル(Unknown Source)
 at java.net.URLClassLoader1ドル.run(Unknown Source)
 at java.net.URLClassLoader1ドル.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?

asked Oct 20, 2014 at 9:31
17
  • If you created project in Eclipse then try changing project facet Java to 1.7 & compiler version to 1.7. Then try to run jar with system having JDK 1.7. Commented Oct 20, 2014 at 9:50
  • @OO7 I am using CMD and notepad, no IDEs Commented Oct 20, 2014 at 9:56
  • What is target system OS ? Commented Oct 20, 2014 at 10:05
  • Target may be start from java 7.0 and can be java 8.0 also Commented Oct 20, 2014 at 10:07
  • @androidGenX r u running on the JDK 8? and what is your class path set? Commented Oct 20, 2014 at 10:10

1 Answer 1

1

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.

answered Oct 20, 2014 at 9:33
Sign up to request clarification or add additional context in comments.

10 Comments

I tried but I am getting error in compilation like 'javac: target version 1.7 conflicts with default source release 1.8'
@androidGenX: Right - sounds like you can't use the Java 8 language features at all when targeting 1.7 then.
Can you tell how buddy? I tried like this : C:\TIPL\GCST>javac -target 1.7 -classpath lib/xbasej-20091203.jar Example2.java javac: target release 1.7 conflicts with default source release 1.8
@androidGenX: Right, it sounds like you can't use Java 8 language features when targeting 1.7, so just use -source 1.7. I've updated my answer.
1.8?? can you write here??
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.