It's easy to compile your Java sources with --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>But how can you then run exec:java? Using<!-- 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>Still results in the following error: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' 解决方案 The problem is that exec:java runs in the same maven java process, which by default isn't started with --enable-preview.You could instead switch to exec:exec, but one way to still use exec:java is to create a .mvn/jvm.config file containing --enable-preview. You can put this in your project's root directory and check into git. Or create a MVN_OPS environment variable.Reference: https://maven.apache.org/configure.html 这篇关于具有预览功能的Maven Exec插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 08:14