|
Resource LoadingThere are a number of ways that Java supports finding and opening resources:
Resource OrderingOne-Jar defines a predictable order for classloading:
Duplicate ResourcesEvery Jar file has a requiredMETA-INF/MANIFEST file. With more than one Jar
inside a One-Jar executable there will therefore be duplicates. Fortunately, this file is not a problem,
since a normal Java application usually has many Jar files (or other codebases) on its classpath,
meaning that it must use scanning to locate its own MANIFEST resources. One-Jar will
have no impact in this situation.
An Example: Log4jWhen multiple Jar files contain a resource with the
same name, e.g. a
Consider a One-Jar which is composed of main.jar, library-a.jar, and library-b.jar. Suppose
that each of these Jar files contains a log4j.properties file. Whichever Jar file initializes
the Log4j subsystem by invoking Logger.getLogger(Class) will trigger the loading of log4j.properties.
Which one will be chosen depends on the order that the JarClassLoader encountered them
during the One-Jar bootstrap process. Fortunately this is well defined, the One-Jar order is:
Consequently, to ensure proper initialization, just make sure that there is a <one-jar destfile="build/${test}-one-jar-log4j.jar"> <file include="log4j.properties"/> <manifest> ... etc.Since One-Jar delegates to the parent classloader which loads the One-Jar file, any top-level resources (or classes) will take precedence over those in the bundled Jar files. |
|
![]() |
![]() |
![]() |