Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 /home/jdk7)

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

like image 708
thd Avatar asked Mar 21 '23 17:03

thd


1 Answers

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.

like image 68
millimoose Avatar answered Apr 12 '23 23:04

millimoose