Using Maven 'exec:exec' with Arguments

前端 未结 1 739
陌清茗
陌清茗 2020-12-14 02:54

I have a project configured to build and run with Maven. The project depends on platform specific native libraries, and I\'m using the strategy found here to manage those d

相关标签:
1条回答
  • 2020-12-14 03:10

    I managed to find a reasonably elegant solution to my problem using Maven environment variables.

    The default values are defined as properties in the pom, and added to the exec plugin as arguments:

    ...
    <properties>
        <argumentA>defaultA</argumentA>
        <argumentB>defaultB</argumentB>
    </properties>
    ...
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
            <executable>java</executable>
            <arguments>
                <argument>-Djava.library.path=${project.build.directory}/lib</argument>
                <argument>-classpath</argument>
                <classpath />
                <argument>com.example.app.MainClass</argument>
                <argument>-a</argument>
                <argument>${argumentA}</argument>
                <argument>-b</argument>
                <argument>${argumentB}</argument>
            </arguments>
        </configuration>
    </plugin>
    ...
    

    Now I can run with default parameters exactly as I did before:

    mvn exec:exec
    

    And I can easily override the defaults for each argument at the command line using:

    mvn exec:exec -DargumentA=alternateA -DargumentB=alternateB
    
    0 讨论(0)
提交回复
热议问题