A simple Windows GUI utility to quickly switch between multiple installed Java JDK versions. This tool automates the process of updating the JAVA_HOME
and Path
environment variables.
(Feel free to replace this with your own screenshot. You can upload an image to your GitHub issue tracker and use the link.)
For developers working on multiple projects, it's often necessary to switch between different versions of the Java Development Kit (JDK). Manually editing environment variables is tedious and error-prone. This tool provides a straightforward graphical interface to handle this task with a single click.
- Automatic Detection: Scans the default
C:\Program Files\Java\
directory for installed JDKs. - Simple Interface: Presents available JDK versions in a clean dropdown menu.
- Environment Variable Management:
- Sets the
JAVA_HOME
environment variable to the selected JDK path. - Updates the system
Path
variable by removing old Java paths and adding the new one.
- Sets the
- Real-time Log: Displays the operations being performed in a text area for transparency.
- Lightweight: A single, standalone executable with no external dependencies required to run.
This tool is designed with specific assumptions:
- Windows Only: It uses the Windows
setx
command to modify environment variables and will not work on macOS or Linux. - Administrator Privileges: To modify system environment variables for all users, you must run the application as an administrator.
- Default JDK Location: It looks for JDKs only in
C:\Program Files\Java\
. - JDK Naming Convention: It assumes your JDK folders are named starting with
jdk-
(e.g.,jdk-11.0.15
,jdk-17.0.2
).
- Download: Go to the Releases page of this repository and download the latest
SwitchJavaGUI.exe
(or.jar
) file. - Run as Administrator:
- Right-click the downloaded
.exe
or.jar
file. - Select "Run as administrator". This is crucial for the environment variable changes to take effect properly.
- Right-click the downloaded
- Select a Version: Choose your desired JDK version from the dropdown list.
- Switch: Click the "Switch Version" button.
- Verify: The log area will show the results of the operation.
Note: Changes to environment variables will not affect any command prompt or terminal windows that are already open. You must open a new command prompt to see the new Java version take effect. You can verify the change by running:
java -version
# and
echo %JAVA_HOME%
The tool performs the following actions when you click "Switch Version":
- Sets
JAVA_HOME
: It executes the commandsetx JAVA_HOME "C:\Program Files\Java\jdk-xx.x.x"
to create or update theJAVA_HOME
variable. - Updates
Path
:- It reads the current system
Path
. - It removes any existing entries that point to a Java installation (specifically paths containing
Java\jdk-
orCommon Files\Oracle\Java\javapath
). - It prepends the
bin
directory of your selected JDK (e.g.,C:\Program Files\Java\jdk-xx.x.x\bin
) to thePath
. - It saves the new
Path
using thesetx
command.
- It reads the current system
Using setx
makes the changes permanent for your user account (or for the entire system if run as an administrator).
If you want to modify the tool or build it yourself, you'll need a JDK installed.
-
Clone the repository:
git clone https://github.com/your-username/your-repository.git cd your-repository
-
Compile the Java code:
javac SwitchJavaGUI.java
-
Run the application:
java SwitchJavaGUI
-
(Optional) Create a runnable JAR file:
jar cfe SwitchJavaGUI.jar SwitchJavaGUI SwitchJavaGUI.class
You can then run the application by double-clicking
SwitchJavaGUI.jar
or from the command line withjava -jar SwitchJavaGUI.jar
.
This is a simple tool with room for improvement.
Current Limitations:
- Windows only.
- Hardcoded JDK search path (
C:\Program Files\Java\
). - Requires manual "Run as administrator".
Potential Future Features:
- Support for macOS and Linux.
- A "Browse" button to allow users to specify a custom directory for JDKs.
- Automatically request administrator elevation.
- Option to set variables for the current User or the entire System.
- Better detection of different JDK distributions (e.g., AdoptOpenJDK, Zulu, Corretto).
Contributions are welcome! If you have an idea for an improvement or find a bug, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.