Specify the order in which configuration files and classes are loaded in Java

The problem you want to solve

--When executing WAR, if there are multiple configuration files with the same name on the classpath for some reason, you want to specify the order in which they are loaded. --Environment assumes WebSphere Liberty, Java 8 --There are three simple ways to include the configuration file and class in the classpath. I want to check these three priorities --Include in WAR file --Include in JAR file and place in WEB-INF / lib of WAR file --Place outside WAR (specify in <library> in Liberty's server.xml)

Result from the research

The order was as follows. Since 1 and 2 are difficult to set freely due to the packaging method and the arrangement of environment-dependent files, if you want to specify the loading order in detail, place the JAR outside the WAR, and then <library> It seems good to specify the order in detail in .

  1. Include in WAR file
  2. Include it in the JAR file and place it in the WAR file WEB-INF / lib
  3. Place outside of WAR (specify in <library> in Liberty's server.xml)

Specifically, it has such a shape. The order of specifying the child elements of <library> is the order of class loading. When not only <file> but also <folder> is specified, the order of XML elements is the order of class loading.

<library id="mydir">
  <file name="/mydir/foo1.jar"/>
  <file name="/mydir/foo2.jar"/>
</library>

<webApplication location="/dir/bar.war">
  <classloader privateLibraryRef="mydir"/>
</webApplication>

What I didn't understand

It seems that the same setting can be made by specifying Class-Path of MANIFEST.MF, but if it is specified by Class-Path of MANIFEST.MF included in WAR, it will not be the target of class loading for some reason. It was like.

Recommended Posts

Specify the order in which configuration files and classes are loaded in Java
Java classes and instances to understand in the figure
Specify the java location in eclipse.ini
[Java] Get the dates of the past Monday and Sunday in order
Java Two Lists are ignored in order, null is ignored, and duplicates are ignored.
Reading and writing gzip files in Java
A note on the differences between interfaces and abstract classes in Java
Regarding the transient modifier and serialization in Java
About the idea of anonymous classes in Java
Differences in writing Java, C # and Javascript classes
Import files of the same hierarchy in Java
[Java] [javaSliver] The interface and abstract classes are complicated, so I will summarize them.
Write ABNF in Java and pass the email address
About the difference between classes and instances in Ruby
Which is better, Kotlin or Java in the future?
java (classes and instances)
[For beginners] Explanation of classes, instances, and statics in Java
JSON in Java and Jackson Part 1 Return JSON from the server
[Java] ArrayList → Should I specify the size in array conversion?
Identify threads in the Java process that are wasting CPU
Correct the character code in Java and read from the URL
Same judgment / equal value judgment / comparison / order in Swift and Java
Think about the differences between functions and methods (in Java)
Let's implement the condition that the circumference and the inside of the Ougi shape are included in Java [Part 2]
Let's implement the condition that the circumference and the inside of the Ougi shape are included in Java [Part 1]
Read binary files in Java 1
[Java] Generics classes and generics methods
Read binary files in Java 2
About abstract classes in java
Java abstract methods and classes
Sort List in descending order in Java and generate a new List non-destructively
[Java] Various summaries attached to the heads of classes and members
Exporting project and war files when creating server-side Java in Eclipse
Spring validation was important in the order of Form and BindingResult
Determine if the strings to be compared are the same in Java