Reputation: 6741
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
You can see the plugin section bellow
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<scope>system</scope>
<systemPath>${JDK_HOME}/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myArtifact</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.mycompany.MyMainClass</argument>
</arguments>
</configuration>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
Upvotes: 4
Views: 9756
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
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