Search code examples
javaeclipsemavenarguments

How to pass args to application from Eclipse Maven Run configurations


I have a Java / Maven project in Eclipse 2023-06. If I want to run the application, I am using a run configuration based on Maven, as depicted in below picture. I can't figure out how to pass an argument to the application - in other words, arguments passed to "public static void main(String[] args)" - without defining a environment variable in the Run Configurations dialog

Eclipse Run Configurations

like it is possible to define it in the Java Application dialog

Java Application Run Configuration

Is there a way to do this directly without checking environment variables?


Solution

  • When running Maven, any parameters are passed to the Maven build. If, like in your case, you have a plugin which also executes the application, then you have to check the plugin's documentation to see how arguments have to be passed.

    The javafx-maven-plugin has a commandlineArgs option which you can use to set application arguments, as shown in the example:

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

    To make the arguments configurable in the Eclipse launch configuration, you can use a Maven property here:

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

    and then define yourapp.commandlineArgs in the parameters table in the launch configuration's main tab.