users@jaxb.java.net

Re: CLASSPATH and bindings with existing classes?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 07 Jan 2003 08:49:41 -0800

> Therefore my class 'URLConverter' is used by the generated binding code,
> and it must be present when the binding is compiled; but how can I tell
> the XJC compiler where I've put it??? It gives me a NoClassDefFoundError.

Technically, all you need to do is to make that class available to the
system class loader.

However, I realized that as you pointed out, this can be quite awkward.

> XJC xeems to have no options for setting its classpath. The classpath of
> the DOS shell from which I run XJC is ignored.

I think having the "-classpath" option just like javac would be the best
solution to this problem, but you are right that we don't have such an
option right now.

> I tried modifying the XJC.BAT script to set the -classpath option in the
> JAVA command that runs the binding compiler. Since THAT makes no
> difference, I assume XJC makes an internal ClassLoader and does NOT hang
> it under the system loader.

The problem is that when you run java with the "-jar" option, all the
"-classpath" option will be ignored. This is by design of java VM.


> Right now the only workaround that I know is to zip up my URLConverter
> and other classes, and install the zip as an extension (place it in the
> ext folder). This is not a long-term solution!

Right.

Another workaround is to use ant. When you define XJC task in Ant, you
can include your URLConverter in the classpath of <taskdef>.

See doc/ant.html for details.


regards,
--
Kohsuke KAWAGUCHI                  408-276-7063 (x17063)
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com