使用 Jetty 的 setExtraClasspath 时,预期的资源加载优先级是多少?
What's the expected resource loading priority when Jetty's setExtraClasspath is used?
是否预计通过 Jetty 的 WebAppContext.setExtraClasspath 方法包含的 .jar 文件中的资源将优先于 .war 中具有相同 name/path 的资源加载?
——
我正在将一些依赖项移出 .war 文件并通过 WebAppContext 的 setExtraClasspath 方法包含它们 (http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html#using-extra-classpath-method)
在这样做的同时,我 运行 遇到了一个问题,其中一个 .jar 文件现在移出包含一个 ehcache.xml 文件,该文件似乎比 .jar 文件中的文件更受欢迎。 war 当使用 Thread.currentThread().getContextClassLoader().getResourceAsStream(“ehcache.xml”)
时。
既然我知道是这种情况,我想如果我需要将文件重命名为唯一的,这对我来说并没有太大的不便,但我想我想知道……
我是否错误地加载了资源(如果是,我怎样才能使 .war 优先)?
之前 .war 版本优先(当有问题的 .jar 打包在 .war 中时)只是运气吗?
这是我不得不忍受的使用 setExtraClasspath 的预期缺点吗?
我是否遗漏了一些可以为我澄清这一点的文档?
感谢Jan on the jetty-user's list...
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.
我的情况很难过,但有道理。
是否预计通过 Jetty 的 WebAppContext.setExtraClasspath 方法包含的 .jar 文件中的资源将优先于 .war 中具有相同 name/path 的资源加载?
——
我正在将一些依赖项移出 .war 文件并通过 WebAppContext 的 setExtraClasspath 方法包含它们 (http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html#using-extra-classpath-method)
在这样做的同时,我 运行 遇到了一个问题,其中一个 .jar 文件现在移出包含一个 ehcache.xml 文件,该文件似乎比 .jar 文件中的文件更受欢迎。 war 当使用 Thread.currentThread().getContextClassLoader().getResourceAsStream(“ehcache.xml”)
时。
既然我知道是这种情况,我想如果我需要将文件重命名为唯一的,这对我来说并没有太大的不便,但我想我想知道……
我是否错误地加载了资源(如果是,我怎样才能使 .war 优先)?
之前 .war 版本优先(当有问题的 .jar 打包在 .war 中时)只是运气吗?
这是我不得不忍受的使用 setExtraClasspath 的预期缺点吗?
我是否遗漏了一些可以为我澄清这一点的文档?
感谢Jan on the jetty-user's list...
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.
我的情况很难过,但有道理。