arsenal11 arsenal11 - 2 years ago 250
Java Question

Specifying a default argument in pom.xml and overriding it in the command line

The only function of my main class is to read from an xml config file, which I'm currently specifying in the command line. Is it possible to make it so a default config file is specified in pom.xml, so if the program is run from the command line without passing in an argument, that config file is read, but if an argument is passed in with -Dexec.args the default is overridden?

Answer Source

at first look at exec plugin documentation here

in your maven in properties specify your default property which you want look at

<project xmlns=""


        <!-- frameworks -->

        <!-- properties -->



here is java class

package test;


public class Test {

    public static void main(String[] args) {
                .forEach(arg -> System.out.println("ARGUMENT " + arg));

and if you execute mvn compile exec:java you should see somewhere outpu ARGUMENT MAVEN. If you provide your own argument eg. mvn compile exec:java you should see ARGUMENT TEST somewhere in console.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download