(This seems like a trivial enough problem, but stuck for 2 days :( )
I have a runnable jar (created with maven assembly plugin
). A class inside the jar looks for an xml file on classpath. However, we do not want to bundle the xml file in the jar and want it to be externalized.
Tried till now:
Set the classpath at runtime:
java -classpath ./conf -jar my-jar-with-dependencies.jar
==> doesn't load (conf folder contains the xml)
Set classpath in assembler plugin
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.xxx.Test</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>./conf/</classpathPrefix>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
==> does not add ClassPath to MANIFEST.MF in the runnable jar
Edit:
Generated MAINFEST.MF
in the jar:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: xxx
Build-Jdk: 1.7.0_21
Main-Class: com.xxx.Test
Edit 2:
So I edited the generated MANIFEST
in the jar and recreated jar. Still doesn't find the xml!
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: xxx
Build-Jdk: 1.7.0_21
Main-Class: com.xxx.Test
Class-Path: . /* Tried with both . and ./conf */
When you use -jar
argument classpath you specify is ignored. It is specified here
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
JVM use classpath specified in manifest. Make sure that manifest contains classpath definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With