Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Running web apps using jetty in Eclipse causes loader.getResource() to return matching xml files in jar files twice

I have been having this problem since at least jetty 6.1.14 and am
still having it with the Jetty 7.6 snapshot.

Running web apps using jetty from Eclipse causes loader.getResource()
to return matching jar files twice.

I've had it happen with Eclipselink xml files, with JSF (Myfaces) xml
files, and now with richfaces xml files.

Ie:

jar:file:/home/mkienenb/[...]/WEB-INF/lib/richfaces-components-ui-4.1.0.20111101-M4.jar!/META-INF/csv.xml
jar:file:/home/mkienenb/[...]/WEB-INF/lib/richfaces-components-ui-4.1.0.20111101-M4.jar!/META-INF/csv.xml

or

Nov 22, 2011 3:41:35 PM
org.apache.myfaces.config.DefaultFacesConfigurationProvider
getClassloaderFacesConfig
INFO: Reading config :
jar:file:/home/mkienenb/[...]/WEB-INF/lib/j4j.jar!/META-INF/faces-config.xml
[...]
Nov 22, 2011 3:41:36 PM
org.apache.myfaces.config.DefaultFacesConfigurationProvider
getClassloaderFacesConfig
INFO: Reading config :
jar:file:/home/mkienenb/[...]/WEB-INF/lib/j4j.jar!/META-INF/faces-config.xml



I run the web apps with a relatively simple launch configuration which
boils down to the following, and there's very llittle going on in my
jetty.xml file.

org.eclipse.jetty.start.Main
-Djetty.webappRootDir=${workspace_loc:myproject}
eclipse/launch-configs/jetty7-debug-myproject.xml

    <New id="myproject" class="org.eclipse.jetty.webapp.WebAppContext">
      <!-- pass in "contexts" that was defined above as a Handler  -->
      <Arg><Ref id="contexts"/></Arg>
      <Arg><SystemProperty name="jetty.webappRootDir" default="." /></Arg>



I tried tracking down the exact cause, but the best I could determine is that

sun.misc.Launcher$AppClassLoader(ClassLoader).getResources(String)
and
org.eclipse.jetty.webapp.WebAppClassLoader.getResources(String)
each return a copy of the matching jar file.

Creating a custom UniquingWebAppClassLoader subclass of
WebAppClassLoader which replaces

    public Enumeration<URL> getResources(String name) throws IOException
    {
[...]
        from_webapp.addAll(from_parent);

with
            addAllUniqueToList1(from_parent, from_webapp);
[...]
    private <T> void addAllUniqueToList1(List<T> list1, List<T> list2) {
    	for (T t : list2) {
			if (!list1.contains(t)) {
				list1.add(t);
			}
		}

works around the problem.


Back to the top