Avner Levy
Avner Levy

Reputation: 6741

Adding command line parameters to maven exec plugin

I'm trying to run a java program using the maven exec plugin using the exec:exec goal.
I need to add an additional jar to the classpath (the sun tools jar).
Since the includePluginDependencies works only for the exec:java goal I thought adding it manually in the arguments section but couldn't find a way to concatenate it to the base classpath. The problem is that since the jar is defined as system scope, maven won't add it to the run-time classpath and I need to add it manually.
If someone knows how to do so from the command line it's even better. Thanks in advance,
Avner

Upvotes: 4

Views: 9756

Answers (3)

noahlz
noahlz

Reputation: 10311

Try adding

<argument>-Xbootclasspath/a:${env.JAVA_HOME}/lib/tools.jar</argument>

From the command line, add

-Dexec.args="-Xbootclasspath/a:$JAVA_HOME/lib/tools.jar"

Another option is to declare the tools.jar as a System dependency and then set the exec plugin scope to "system." See: exec-maven-plugin - classpathScope

Upvotes: 1

Avner Levy
Avner Levy

Reputation: 6741

Eventually I've decided to use the maven-antrun-plugin so here is a possible alternative solution.

<configuration>
<target>
    <property name="runtime_classpath" refid="maven.runtime.classpath"/>

    <java classname="com.mycompany.MyClass"
            fork="true"
            spawn="false"
            failonerror="true"
            maxmemory="512m" >

        <classpath>
            <pathelement path="${runtime_classpath}" />
            <pathelement path="${JDK_HOME}/lib/tools.jar" />
        </classpath>
        <arg value="${ant.param1}" />
        <arg value="${ant.param2}" />
        <arg value="${ant.param3}" />
        <arg value="${ant.param4}" />
        <arg value="${ant.param5}" />
    </java>
</target>
</configuration>

Upvotes: 2

gkamal
gkamal

Reputation: 21000

You can try setting the CLASSPATH environment variable.

Upvotes: 1

Related Questions