Ray_Write
Ray_Write

Reputation: 131

Multiple java versions on Windows

I see this question has been addressed here Multiple Java versions running concurrently under Windows, I think some things have changed since this question was addressed.

I want to run multiple versions of java on Windows 10. While investigating this I see that Oracle (I think) has modified the PATH env variable on my machine. There are 2 entries:

C:\Program Files (x86)\Common Files\Oracle\Java\javapath

C:\ProgramData\Oracle\Java\javapath

Both of these entries are symbolic links to my default version of java , 1.10 in my case. I think the easiest way to run multiple versions is to remove both of these entries, add a JAVA_HOME env variable and add %JAVA_HOME%\bin to my PATH env variable. When I want to change java versions I just change my JAVA_HOME variable.

I'm wondering if people think this is the best way to accomplish what I want and also does anyone know why there are 2 different entries pointing to symbolic links for java.

Upvotes: 2

Views: 8497

Answers (2)

SwaPpeR
SwaPpeR

Reputation: 68

On macOS, one can use jENV to manage multiple java versions. There is an alternative of this in Windows - https://github.com/FelixSelter/JEnv-for-Windows/blob/main/jenv.bat

Upvotes: 1

Bill K
Bill K

Reputation: 62789

I tend to remove all the java variables from the system and put them in the batch file used to start my java app(s)--if you do this you keep complete control across versions.

Even though java apps tend to work on newer java versions, sometimes a program will install an older java version and modify your path/env, so you should probably have your batch file put your desired java bin path at the head of the path variable and overwrite the java_home variable (I think java_opts is used as well and could be set by your batch file).

You can also have a batch file add to the path and then run "CMD" which launches a new shell. This allows you to develop or run java straight from the command line without permanently modifying your environment.

Java never has a simple command line, so I'd think anyone that had to type java -jar … even once would want to build a batch file so they could just launch it like any .exe anyway, so why not set up your environment in there as well?

Upvotes: 1

Related Questions