How does the Java – runnable jar load external XML files at runtime?

(this seems to be a trivial problem, but it lasted for 2 days: ()

I have a runnable jar (created using the Maven assembly plug-in) The class in jar looks for the XML file in the classpath However, we don't want to bundle jar files into jars and externalize them

Tried until now:

>Set classpath at run time:

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

==>Do not load (CONF folder contains XML)

>Set classpath in assembler plug-in

<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 will not be added to manifest.path in runnable jar MF

Edit:

Generate mainfest.jar in jar 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

Edit 2:

So I edited the generated manifest in jar and recreated the jar Still no XML found!

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 */

Solution

When using the - jar parameter classpath, the specified content will be ignored It is designated here

The JVM uses the classpath specified in the manifest Make sure the manifest contains the classpath definition

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>