kan*_*ics 5 java maven maven-exec-plugin preview-feature java-14
使用以下命令可以轻松编译 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>
Run Code Online (Sandbox Code Playgroud)
但你怎么能跑呢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>
Run Code Online (Sandbox Code Playgroud)
仍然会出现以下错误:
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'
Run Code Online (Sandbox Code Playgroud)
问题是 exec:java 在同一个 maven java 进程中运行,默认情况下不以--enable-preview
.
您可以改为切换到exec:exec
,但仍然使用 exec:java 的一种方法是创建一个.mvn/jvm.config
包含--enable-preview
. 您可以将其放在项目的根目录中并签入 git。或者创建一个 MAVEN_OPTS 环境变量。
参考: https: //maven.apache.org/configure.html
归档时间: |
|
查看次数: |
1419 次 |
最近记录: |