Skip to content

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.

License

Notifications You must be signed in to change notification settings

MenuraDev/Java-Version-Switcher

Repository files navigation

Java Version Switcher GUI

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

Overview

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.

Features

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

⚠️ Important Prerequisites

This tool is designed with specific assumptions:

  1. Windows Only: It uses the Windows setx command to modify environment variables and will not work on macOS or Linux.
  2. Administrator Privileges: To modify system environment variables for all users, you must run the application as an administrator.
  3. Default JDK Location: It looks for JDKs only in C:\Program Files\Java\.
  4. JDK Naming Convention: It assumes your JDK folders are named starting with jdk- (e.g., jdk-11.0.15, jdk-17.0.2).

Installation and Usage

  1. Download: Go to the Releases page of this repository and download the latest SwitchJavaGUI.exe (or .jar) file.
  2. 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.
  3. Select a Version: Choose your desired JDK version from the dropdown list.
  4. Switch: Click the "Switch Version" button.
  5. 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%

How It Works

The tool performs the following actions when you click "Switch Version":

  1. Sets JAVA_HOME: It executes the command setx JAVA_HOME "C:\Program Files\Java\jdk-xx.x.x" to create or update the JAVA_HOME variable.
  2. Updates Path:
    • It reads the current system Path.
    • It removes any existing entries that point to a Java installation (specifically paths containing Java\jdk- or Common 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 the Path.
    • It saves the new Path using the setx command.

Using setx makes the changes permanent for your user account (or for the entire system if run as an administrator).

Building from Source

If you want to modify the tool or build it yourself, you'll need a JDK installed.

  1. Clone the repository:

    git clone https://github.com/your-username/your-repository.git
    cd your-repository
  2. Compile the Java code:

    javac SwitchJavaGUI.java
  3. Run the application:

    java SwitchJavaGUI
  4. (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 with java -jar SwitchJavaGUI.jar.

Limitations & Future Improvements

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

Contributing

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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages