Sergey Aldoukhov
Sergey Aldoukhov

Reputation: 22744

How to add a classpath entry when executing the app with exec plugin

One of the components is looking for the persistence.xml using the java.class.path system property. It is desired to keep this file separately from jars in the /conf folder.

When running the app with exec:exec, classpath is formed from the path to the main jar plus path to every dependency. I can't seem to figure out how to add the /conf entry to the classpath.

My command line looks like this:

mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath com.testjar.App"

I tried "arguments" parameter but the execution fails if I try to append anything to %classpath. I also tried to add a Class-Path entry to the manifest by specifying

<manifestEntries>
  <Class-Path>/conf</Class-Path>
</manifestEntries>

in the configuration for maven-jar-plugin, but the entry in the manifest has no effect on the value of java.class.path property.

Upvotes: 3

Views: 6248

Answers (1)

Boris Pavlović
Boris Pavlović

Reputation: 64650

You may use the element 'resources' in the 'build' section of your POM file. For example

<build>
 <resources>
  <resource>
   <directory>src/main/resources/config</directory>
   <includes>
    <include>persistence.xml</include>
   </includes>
   <targetPath>/</targetPath>
  </resource>
 </resources>
 ...
</build>

This will copy the persistence.xml into the build output directory, i.e. it will place the persistence.xml on the classpath.

Upvotes: 4

Related Questions