v4r v4r - 1 year ago 93
Java Question

Running jar created in Java 7 in a Java 6 environment

I have a jar file that I created on my PC using Java 7. I want to run it on my lab server which only has Java 6. I try to run the jar file:

java -jar file.jar
but there was a UnsupportedClassVersionError exception.

Since I have no root right, I cannot install the new Java 7 on the server. However, I can download JDK7 to my working folder (let say

Is there a way to run the jar file by specifying the jdk path to /home/jdk7 ?

Answer Source

You can use the java executable from your private JRE/JDK installation explicitly. If it's installed in /home/jdk7/, the full command line should be:

/home/jdk7/bin/java -jar file.jar …

Alternately, you can make this installation's executables the "default" by prepending them to your PATH, by using the following in ~/.bashrc or ~/.profile. (One of those or both will be correct for your lab system, I'm not sure since I use fish.)

export PATH=/home/jdk7/bin:$PATH

Note: this will only help if it's in the environment of the logged in user.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download