Currently I have Java 1.6 and Java 1.8 installed in my computer. I have set the path of Java 1.8 in the environment variable and it is running fine. But in some programs, I need to use Java 1.6. So how can I change the active version of Java through command line so that I can compile and run it using Java 1.6? (I use notepad++ to write the code and command prompt to compile and run it).
1 Answer
javac -target 1.6 <source files>.
For Eclipse or other IDE (build jars) you need to specify there the version.
java ...
, your system-wide Java-related settings will be completely unaffected, because the scope is much bigger than just your terminal emulator and the shell. Do you just want to control which Java runs on the command line? Then inspect and adjust yourPATH
variables accordingly, and perhaps some other Java-related environment variables, if required. You can also plain and simple run your desired java like/opt/local/java-1.6/bin/java -jar MyClass.jar
or similar.