Is there a way to change JDK version easily in cmd? like the version on mac. Change Default JDK on Mac.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
In "System Properties" window, click “Environment Variables…” and select
PATH
by click on Edit, then "New" and type ;%JAVA_HOME%\bin
It will write the
JAVA_HOME
defined. Just to edit one time.And after you define
JAVA_HOME
by the cmd commande :set JAVA_HOME = path_of_jdk_or_jre
whenever you want.I created batch scripts for every version of Java that I have installed on my PC, and use those whenever I need to change the Java version through the command line. Here is an example of one, should be self-explanatory really:
Here's my guide for Windows 10.
Step 1. Go to System Properties. Click on
Environment Variables
Step 2. Add new variables, such as JAVA_8_HOME
JAVA_8_HOME
:%ProgramFiles%\Java\jdk1.8.0_152\bin
JAVA_9_HOME
:%ProgramFiles%\Java\jdk-9.0.1\bin
JAVA_HOME
:%JAVA_8_HOME%
In my case,
JAVA_8_HOME
(JDK8) is pointing toC:\Program Files\Java\jdk1.8.0_152\bin
. You can replace this with your own path tojavac
.%JAVA_HOME%
has a default value pointing toJAVA_8_HOME
, which is the path for JDK8. That's my preference, feel free to adjust accordingly.Step 3. Select
PATH
and click onEdit
. PATHStep 4. Click on
New
and add %JAVA_HOME%.%JAVA_HOME%
will be added toPATH
automatically every time you launch a command prompt.In order to switch JDK version in cmd, here's the trick. Step 5. I created a batch file with
Basically, it disables echo and creates two alias. In batch file any string after
::
is the comments. Every time,java8
orjava9
is called, it re-exports %PATH% with the new JDK path. Save it asprofile.bat
. You can name it whatever you want.Step 6. Search for
regedit
(Registry Editor). Click onEdit
>New
>String Value
. GiveAutoRun
as theValue name
and%USERPROFILE%\profile.bat
as theValue data
. Here, please put your actual path value to theprofile.bat
we just created. So, whenever a command prompt is opened, it automatically loadsprofile.bat
, which creates those two alias in the script.Step 7. Close any command prompt you're using or just open a new command prompt. This is because your changes will not affect opened cmd window. Environment changes only happens to new CMD.
Step 8. Verify your results here.
If you're using different Python versions, same trick applies, too. Find my python environment settings here.