【问题标题】:Maven Exec Plugin with Preview Features具有预览功能的 Maven Exec 插件
【发布时间】:2020-07-10 08:48:37
【问题描述】:

使用--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'

【问题讨论】:

  • 在 Java-12 开发期间,我记得使用 shade 插件尝试过这个,创建一个 jar 并使用 java 命令行执行,列出的步骤under this Q&A

标签: java maven maven-exec-plugin java-14 preview-feature


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 2018-07-10
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2018-04-12
    相关资源
    最近更新 更多