我在 Eclipse 2023-06 中有一个 Java / Maven 项目。如果我想运行该应用程序,我将使用基于 Maven 的运行配置,如下图所示。我不知道如何将参数传递给应用程序 - 换句话说,参数传递给“public static void main(String[] args)” - 无需在“运行配置”对话框中定义环境变量
就像可以在 Java 应用程序对话框中定义它一样
有没有办法直接做到这一点而不检查环境变量?
运行 Maven 时,任何参数都会传递给 Maven 构建。如果像您的情况一样,您有一个也执行应用程序的插件,那么您必须检查插件的文档以了解如何传递参数。
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
。