0

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).

6
  • How do you want to call those programs? what kind of programs (jar ?)? Oct 5, 2017 at 13:34
  • Possible duplicate of How do i compile a .java with support for older versions of java? Oct 5, 2017 at 13:34
  • "Command line" is a typically a shell running in a terminal emulator. Unless you will run Java programs from that shell like 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 your PATH 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. Oct 5, 2017 at 13:37
  • If you are building from Eclipse : you can change the active JRE in Windows/Preferences/Installed JRE then you have to define Compiler Compliance to 1.6 in Windows/Preferences/Compiler/Builder
    – Tuco
    Oct 5, 2017 at 13:45
  • 2
    Update your question tag java and used OS, It makes your question more specific..
    – user4856296
    Oct 5, 2017 at 13:52

1 Answer 1

0
javac -target 1.6 <source files>.

For Eclipse or other IDE (build jars) you need to specify there the version.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.