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 dependencies.
Essentially, the .dll
or .so
files for a particular platform are packaged into a jar, and pushed to the Maven server with a classifier identifying the target platform. The maven-dependency-plugin then unpacks the platform specific jar, and copies the native libraries to the target folder.
Normally I would use mvn exec:java
to run a Java program, but exec:java
runs applications in the same JVM as Maven, which prevents me from modifying the classpath. Since the native dependencies must be added to the classpath, I am forced to use mvn exec:exec
instead. This is the relevant snippet of the pom:
...
<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=target/lib</argument>
<argument>-classpath</argument>
<classpath />
<argument>com.example.app.MainClass</argument>
</arguments>
</configuration>
</plugin>
...
This works fine for the default configuration of the application, but I want to be able to specify some optional parameters at the command line. Ideally, I'd like to do something like this:
mvn exec:exec -Dexec.args="-a <an argument> -b <another argument>"
Unfortunately, specifying the exec.args
variable overwrites the arguments I have in the pom (which are required to set up the classpath and run the application). Is there a way around this? What's the best way to specify some optional arguments at the command line without overwriting what I have in the pom?