How to Set Environment Variables for Java in Windows
To set environment variables for Java in Windows, follow these steps:
Setting User Environment Variables
- Open Control Panel and navigate to "System and Security > System."
- Click on "Advanced system settings" and then on the "Environment Variables" button.
- Under "User variables," create or modify the following variables:
- JAVA_HOME: Set to the installation directory of the Java Development Kit (JDK).
- JDK_HOME: Set to ${JAVA_HOME}.
- JRE_HOME: Set to ${JAVA_HOME}/jre.
- CLASSPATH: Set to .%;${JAVA_HOME}/lib;${JAVA_HOME}/jre/lib.
- PATH: Add ${JAVA_HOME}/bin to the beginning of the path. Ensure there are no other references to Java installation folders.
Optional Recommendations
- Create a user environment variable JAVA_TOOL_OPTIONS with the value -Dfile.encoding="UTF-8" to set the default character encoding to UTF-8.
- Remove the entry C:ProgramDataOracleJavajavapath; from the system environment variable Path if it exists to ensure consistency in the environment setup.
Troubleshooting
- If Java commands do not work, restart the command prompt or terminal for the changes to take effect.
- Verify the values of the environment variables to ensure they point to the correct locations.
- If you encounter any other issues, refer to the Java documentation or consult with a Java developer.
The above is the detailed content of How Do I Set Java Environment Variables in Windows?. For more information, please follow other related articles on the PHP Chinese website!