具有预览功能的Maven Exec插件 [英] Maven Exec Plugin with Preview Features

查看:189
本文介绍了具有预览功能的Maven Exec插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用--enable-preview编译Java源代码很容易:

<!-- 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'

解决方案

问题是exec:java在同一个maven java进程中运行,默认情况下它不以--enable-preview开头.

您可以改用exec:exec,但是仍然使用exec:java的一种方法是创建一个包含--enable-preview.mvn/jvm.config文件.您可以将其放在项目的根目录中并检入git.或创建MVN_OPS环境变量.

参考: https://maven.apache.org/configure.html

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插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆