Enable the Preview Feature in Java 13 with Maven
Preview Feature
A preview feature or VM feature is a new feature of the Java SE Platform.
This article shows you how to use –enable-preview to enable the preview features in Java 13 with maven.
To use preview features in your programs, you must explicitly enable them in the compiler and the runtime system. Because this feature disabled by default.If not, you’ll receive an error message that states that your code is using a preview feature.
Enable all preview features
javac --release 13 --enable-preview HelloWorld.java
Run with preview features
java --enable-preview HelloWorld
Enable preview features in Maven.
Add the following to the pom.xml
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>13</release> <compilerArgs> --enable-preview </compilerArgs> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M3</version> <configuration> <argLine>--enable-preview</argLine> </configuration> </plugin> </plugins> </build>
Related Articles
- Java 13 – New Features Defined in JDK 13
- Java 13 Switch Expression
Pingback: Java 13 Switch Expressions - Sandny Blog()