4

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.

thd
  • 2,380
  • 1
  • 25
  • 33
  • 2
    `/home/jdk7/bin/java -jar file.jar` maybe? That said, the path least annoying here would be to just use JDK6 for developing your labs. (E.g. your instructor might want to test it himself and he wouldn't use your private Java installation.) – millimoose Nov 11 '13 at 15:50
  • Thanks. /home/jdk7/bin/java -jar file.jar works. At least, the jar file is running right now. Please change your comment to an answer. – thd Nov 11 '13 at 16:00

2 Answers2

5

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.

millimoose
  • 39,073
  • 9
  • 82
  • 134
2

You can't. You can run Java 6 projects on Java 7, but not Java 7 projects on Java 6. This is because you can use some instructions in Java 7 that don't exist in Java 6. I've got this problem sometimes too.

pillravi
  • 4,035
  • 5
  • 19
  • 33
LuisSM
  • 57
  • 2
  • 9
  • It's not the problem of running my Java7 project on Java 6 but it's about how to config to run my Java7 project with the JDK7 folder ('/home/jdk7'). By the way, I can use eclipse with JDK7 to run my project on my server :D – thd Nov 11 '13 at 15:58
  • Do you mean something like this? http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime You can get the version of java when you are executing your code. I have found this, maybe this can help you http://stackoverflow.com/questions/222187/how-to-check-jre-version-prior-to-launch :) – LuisSM Nov 11 '13 at 16:09