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

Thanks Jan - The confirmation is certainly helpful.

Is extraClasspath coming before WEB-INF/classes in that list desirable?

I can see an argument for it I suppose, because knowing this I could take someone else’s .war file and selectively replace their classes or resources with an extraClasspath .jar of my own…

In any case, I think it’s clear that I’ll need to resolve the conflict by renaming the resource for the time being.

Cheers,
Matt
 
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
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/misc/URLClassPath.java#URLClassPath.0urls
looks like the search order will be as above.

cheers
Jan

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 (
http://www.eclipse.org/jetty/documentation/current/jetty-
> classloading.html#using-extra-classpath-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,
> Matt



Back to the top