Maven Exec Plugin with Preview Features

蓝咒 提交于 2020-06-13 07:57:18

问题


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'

回答1:


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



来源:https://stackoverflow.com/questions/60922845/maven-exec-plugin-with-preview-features

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!