如何从 Eclipse Maven Run 配置将参数传递给应用程序

问题描述 投票:0回答:1

我在 Eclipse 2023-06 中有一个 Java / Maven 项目。如果我想运行该应用程序,我将使用基于 Maven 的运行配置,如下图所示。我不知道如何将参数传递给应用程序 - 换句话说,参数传递给“public static void main(String[] args)” - 无需在“运行配置”对话框中定义环境变量

就像可以在 Java 应用程序对话框中定义它一样

有没有办法直接做到这一点而不检查环境变量?

java eclipse maven arguments
1个回答
0
投票

运行 Maven 时,任何参数都会传递给 Maven 构建。如果像您的情况一样,您有一个也执行应用程序的插件,那么您必须检查插件的文档以了解如何传递参数。

javafx-maven-plugin 有一个

commandlineArgs
选项,您可以使用它来设置应用程序参数,如示例所示:

<plugin>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>0.0.8</version>
    <configuration>
        <mainClass>org.openjfx.hellofx/org.openjfx.App</mainClass>
        <commandlineArgs>foo</commandlineArgs>
    </configuration>
</plugin>

要在 Eclipse 启动配置中配置参数,您可以在此处使用 Maven 属性:

<commandlineArgs>${yourapp.commandlineArgs}</commandlineArgs>

然后在启动配置主选项卡的参数表中定义

yourapp.commandlineArgs

© www.soinside.com 2019 - 2024. All rights reserved.