How to force a jar to run in java 7?

2.5k Views Asked by At

I made a Runnable Jar that will run as service in windows, but the final pc that will execute him, has 3 versions of java installed, 1.3, 1.6 and 1.7, and my jar needs to be executed with 1.7, because him uses classes that are present only in 1.7+ version, o don't know how are configured the environiment variables, my question is:

Is possible to force my code to run in java 1.7?

3

There are 3 best solutions below

0
On

You can also do this without persistently resetting your path environments. Just use the absolute path to your jre/jdk instead of typing "java": e.g.: "C:\Program Files\Java\jre7\bin"\java -jar foo.jar, same goes for MacOS and Linux.

0
On
  • Rather than setting path/classpath at top level, you should create a batch file and set path/classpath there.

  • Then command to run your jar.

3
On

Set your JAVA_HOME and PATH environment variable to point to the Java 7 directory.

See https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them to know how to do it.