Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Resource loading priority when setExtraClasspath is used

AFAIK we don't do any special handling of the extra classpath.  The order of paths that are added to the URLClassLoader that is the webapp classloader is:

* extra classpath
* WEB-INF/classes
* WEB-INF/lib/*.jar

The webapp classloader getResource(String) method first looks in itself before looking in the parent (to conform to servlet spec inverted classloading requirements), however the looking is all delegated to the URLClassLoader, so it is whatever ordering the jvm has implemented, which according to GrepCode looks like the search order will be as above.


On 21 April 2017 at 13:48, Matthew Sheppard <msheppard@xxxxxxxxxxxxxx> wrote:
TL;DR: Is it expected that resources in .jar files included via WebAppContext’s setExtraClasspath method would be loaded in preference to resources with the same name/path within the .war?


I’m in the process of moving some dependencies out of .war files and including them instead via WebAppContext’s setExtraClasspath method (

While doing so, I ran into a problem where one of the .jar files now moved out contains an ehcache.xml file, which seems to be read in preference to the one within the .war when `Thread.currentThread().getContextClassLoader().getResourceAsStream(“ehcache.xml”)` is used.

Now that I know that to be the case, I guess it’s not a big inconvenience to me if I need to rename the file to be unique, but I guess I’m wondering…

- Am I loading the resource incorrectly (and if so, how can I do it to the .war takes priority)?

- Was it only luck that the .war version took precedence previously (when the .jar in question was packed within the .war)?

- Is this an expected drawback of using setExtraClasspath that I just have to live with?

- Did I miss some documentation somewhere which would have clarified this for me?

Many thanks for any pointers,

jetty-users mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Jan Bartel <janb@xxxxxxxxxxx>
Expert assistance from the creators of Jetty and CometD

Back to the top