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

Puneet
  • 11
  • 3
  • How do you want to call those programs? what kind of programs (jar ?)? – Mohamed Bathaoui Oct 05 '17 at 13:34
  • Possible duplicate of [How do i compile a .java with support for older versions of java?](https://stackoverflow.com/questions/11364761/how-do-i-compile-a-java-with-support-for-older-versions-of-java) – Mohit Tyagi Oct 05 '17 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. – Armen Michaeli Oct 05 '17 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 05 '17 at 13:45
  • Throught the command line, under Windows, just do "set path=myJRE\bin;%path%" before executing java command – Tuco Oct 05 '17 at 13:46
  • 2
    Update your question tag java and used OS, It makes your question more specific.. –  Oct 05 '17 at 13:52

1 Answers1

0
javac -target 1.6 <source files>.

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

Andreea Craciun
  • 302
  • 1
  • 6