Let's say there is a jar main.jar
which depends on two other jars - dep1.jar
and dep2.jar
. Both dependencies are in a classpath in MANIFEST.MF of main.jar
. Each of dependency jars has a directory foo
inside with a file bar.txt
within:
dep1.jar
|
\--foo/
|
\--bar.txt
dep2.jar
|
\--foo/
|
\--bar.txt
Here is a main class of main.jar
:
public class App
{
public static void main( String[] args ) {
ApplicationContext ctx = new StaticApplicationContext();
Resource barResource = ctx.getResource("classpath:foo/bar.txt");
}
}
Which of two bar.txt
files will be loaded? Is there a way to specify in a resource URL a jar the file should be loaded from?
Which one you get is undefined. However, you can use
Resource[] barResource = ctx.getResources("classpath*:foo/bar.txt");
to get them both (all). The URL
in the Resource
will tell you which jar
they are in (though I don't recommend you start programming based on that information).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With