java - How can a runnable jar load external xml file at runtime? -


(this seems trivial enough problem, stuck 2 days :( )

i have runnable jar (created maven assembly plugin). class inside jar looks xml file on classpath. however, not want bundle xml file in jar , want externalized.

tried till now:

  1. set classpath @ runtime:

    java -classpath ./conf -jar my-jar-with-dependencies.jar 

==> doesn't load (conf folder contains xml)

  1. 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> 

==> not add classpath manifest.mf in runnable jar

edit:

generated mainfest.mf in 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 edited generated manifest in jar , recreated jar. still doesn't find 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 both . , ./conf */ 

when use -jar argument classpath specify ignored. specified here

when use option, jar file source of user classes, , other user class path settings ignored.

jvm use classpath specified in manifest. make sure manifest contains classpath definition.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -