(这似乎是一个微不足道的问题,但坚持了2天:()
我有一个可运行的jar(使用maven程序集插件创建). jar中的类在类路径中查找xml文件.但是,我们不希望将jar文件捆绑在jar中并希望将其外部化.
试过到现在:
>在运行时设置类路径:
java -classpath ./conf -jar my-jar-with-dependencies.jar
==>不加载(conf文件夹包含xml)
>在汇编程序插件中设置classpath
<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>
==>不会将ClassPath添加到runnable jar中的MANIFEST.MF
编辑:
在jar中生成MAINFEST.MF:
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
编辑2:
所以我在jar中编辑了生成的MANIFEST并重新创建了jar.仍然没有找到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 */