If you're a Java developer, you've probably encountered the Java Feature Preview warning. This warning is meant to inform you that the Java version you're using has some features that are still in preview mode. While it's important to be aware of these features, the warning message can be annoying, especially if you're working on a project that requires a specific Java version.
In this article, we'll show you how to disable the Java Feature Preview warning. We'll cover different methods to achieve this, and we'll provide step-by-step instructions for each method. By the end of this article, you should be able to disable the Java Feature Preview warning and continue with your development work without any interruptions.
Method 1: Using the JDK Command-Line Option
The first method to disable the Java Feature Preview warning is by using the --disable-preview command-line option. This option is available in JDK 12 and later versions. Here's how to use it:
- Open a command prompt or terminal window.
- Navigate to the directory where your Java project is located.
- Run the following command:
java --disable-preview -jar your-project.jar
Replace your-project.jar with the name of your Java project's JAR file. This command will disable the Java Feature Preview warning for the duration of the Java session.
Method 2: Using the JDK Compiler Option
If you're compiling your Java project using the JDK compiler, you can disable the Java Feature Preview warning by using the -Xlint:-preview compiler option. Here's how to use it:
- Open a command prompt or terminal window.
- Navigate to the directory where your Java project is located.
- Run the following command:
javac -Xlint:-preview YourJavaFile.java
Replace YourJavaFile.java with the name of your Java file. This command will disable the Java Feature Preview warning during the compilation process.
Method 3: Using the JDK Properties File
If you want to disable the Java Feature Preview warning permanently, you can modify the JDK properties file. Here's how to do it:
- Open a text editor, such as Notepad or TextEdit.
- Open the JDK properties file. The location of the file depends on your operating system. For example, on Windows, the file is located at
C:\Program Files\Java\jdk-15.0.1\conf\java.security. - Add the following line to the file:
jdk.compiler.preview=disable - Save the file and close the text editor.
This method will disable the Java Feature Preview warning permanently for all Java projects that use the modified JDK.
Method 4: Using the JDK Environment Variable
If you don't want to modify the JDK properties file, you can disable the Java Feature Preview warning by setting an environment variable. Here's how to do it:
- Open the system properties window. On Windows, you can do this by typing
systempropertiesadvancedin the Start menu search box. On Mac, you can do this by clicking the Apple menu and selecting System Preferences, then clicking the Sharing icon and selecting the Services tab. - Click the Environment Variables button.
- Click the New button.
- In the New System Variable dialog box, enter the following:
- Variable name:
JDK_HOME - Variable value: The path to your JDK installation directory, such as
C:\Program Files\Java\jdk-15.0.1on Windows or/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Homeon Mac. - Click OK to close the New System Variable dialog box.
- Click the New button again.
- In the New System Variable dialog box, enter the following:
- Variable name:
JAVA_TOOL_OPTIONS - Variable value:
-Xlint:-preview - Click OK to close the New System Variable dialog box.
- Click OK to close the Environment Variables window.
- Click OK to close the system properties window.
This method will disable the Java Feature Preview warning permanently for all Java projects that use the JDK specified in the JDK_HOME environment variable.
In this article, we've shown you how to disable the Java Feature Preview warning. We've covered four different methods to achieve this, and we've provided step-by-step instructions for each method. By disabling the Java Feature Preview warning, you can continue with your development work without any interruptions.
If you have any questions or comments, please leave them in the comments section below. We're always here to help you with your Java development needs.
References
| Title | URL |
|---|---|
| Java Platform, Standard Edition 15.0.1 (JDK 15.0.1) Release Notes | https://www.oracle.com/java/technologies/javase-jdk15-relnotes.html |
| Java Platform, Standard Edition Tools Reference | https://docs.oracle.com/en/java/javase/15/docs/specs/man/java.html |
| Java Platform, Standard Edition Compiler Options | https://docs.oracle.com/en/java/javase/15/tools/javac.html#GUID-AEEC9F0E-CB8F-459D-8677-0199E985ABDC |
| Java Platform, Standard Edition Properties | https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/security/Security.html#getProperties() |