使用以下代码编译 Java 源代码很容易--enable-preview
:
<!-- Enable preview features -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>15</release>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
但是你怎么能跑exec:java
呢?使用
<!-- Exec plugin.. run with `mvn exec:java` -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<commandlineArgs>--enable-preview</commandlineArgs>
<arguments>
<argument>--enable-preview</argument>
</arguments>
</systemProperties>
</configuration>
</plugin>
仍然导致以下错误:
An exception occured while executing the Java class.
Preview features are not enabled for Main (class file version 59.65535).
Try running with '--enable-preview'