You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by nicolas de loof <ni...@apache.org> on 2008/08/22 11:29:40 UTC

could the cxf-codegen-plugin use a parent-last classloader to avoid conflict with Java6 JAXB 2.0 API ?

I'm trying to use CXF 2.1.2 codegen, my dev environment beeing based on
jrockit 6.0 - that includes jaxb 2.0 API (as SUN java 6 did prior to update
? )
I get a generation error (with a nice message) due to requirement for JAXB
2.1, but JAXB 2.0 beeing loaded from bootclasspath.

As the cxf-codegen-plugin setup it's custom URLClassLoader with project
classes and dependencies, could it setup a "parent-last" strategy to avoid
such conflict ?

Nicolas.

Re: could the cxf-codegen-plugin use a parent-last classloader to avoid conflict with Java6 JAXB 2.0 API ?

Posted by nicolas de loof <ni...@apache.org>.
metro does something similar (
http://weblogs.java.net/blog/kohsuke/archive/2007/02/howitworks_runn.html)
but the classloader code is under GPL :-/
The general idea of a masking classloader could be used anymay.

2008/8/22 nicolas de loof <ni...@apache.org>

> Something like this ...
>
> /**
>  * A custom ClassLoader to hidde the system classloader JAXB-API that may
>  * be incompaible with requirement for JAXB-2.1
>  */
> public class OverrideJaxbApiClassLoader extends URLClassLoader {
>
>     /** A dedicated classloader to access the JAXB 2.1 API */
>     private URLClassLoader jaxbApiClassloader;
>
>     public OverrideJaxbApiClassLoader(URL jaxbApiURL, URL[] urls,
> ClassLoader parent) {
>         super(urls, parent);
>         jaxbApiClassloader = new URLClassLoader(new URL[] {jaxbApiURL});
>     }
>
>     protected synchronized Class<?> loadClass(String name, boolean resolve)
> throws ClassNotFoundException {
>         if (name.startsWith("javax.xml.bind")) {
>             return jaxbApiClassloader.loadClass(name);
>         } else {
>             return super.loadClass(name, resolve);
>         }
>     }
> }
>
> 2008/8/22 nicolas de loof <ni...@apache.org>
>
> I'm trying to use CXF 2.1.2 codegen, my dev environment beeing based on
>> jrockit 6.0 - that includes jaxb 2.0 API (as SUN java 6 did prior to update
>> ? )
>> I get a generation error (with a nice message) due to requirement for JAXB
>> 2.1, but JAXB 2.0 beeing loaded from bootclasspath.
>>
>> As the cxf-codegen-plugin setup it's custom URLClassLoader with project
>> classes and dependencies, could it setup a "parent-last" strategy to avoid
>> such conflict ?
>>
>> Nicolas.
>>
>>
>

Re: could the cxf-codegen-plugin use a parent-last classloader to avoid conflict with Java6 JAXB 2.0 API ?

Posted by nicolas de loof <ni...@apache.org>.
Something like this ...

/**
 * A custom ClassLoader to hidde the system classloader JAXB-API that may
 * be incompaible with requirement for JAXB-2.1
 */
public class OverrideJaxbApiClassLoader extends URLClassLoader {

    /** A dedicated classloader to access the JAXB 2.1 API */
    private URLClassLoader jaxbApiClassloader;

    public OverrideJaxbApiClassLoader(URL jaxbApiURL, URL[] urls,
ClassLoader parent) {
        super(urls, parent);
        jaxbApiClassloader = new URLClassLoader(new URL[] {jaxbApiURL});
    }

    protected synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
        if (name.startsWith("javax.xml.bind")) {
            return jaxbApiClassloader.loadClass(name);
        } else {
            return super.loadClass(name, resolve);
        }
    }
}

2008/8/22 nicolas de loof <ni...@apache.org>

> I'm trying to use CXF 2.1.2 codegen, my dev environment beeing based on
> jrockit 6.0 - that includes jaxb 2.0 API (as SUN java 6 did prior to update
> ? )
> I get a generation error (with a nice message) due to requirement for JAXB
> 2.1, but JAXB 2.0 beeing loaded from bootclasspath.
>
> As the cxf-codegen-plugin setup it's custom URLClassLoader with project
> classes and dependencies, could it setup a "parent-last" strategy to avoid
> such conflict ?
>
> Nicolas.
>
>