users@jaxb.java.net

Re: Reusing bindings from previous xjc run

From: Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_Sun.COM>
Date: Mon, 25 Oct 2004 11:29:28 -0400

Lachlan O'Dea wrote:
> Hi, I've been having trouble making xjc do what I want.
>

I'm confused by the subject - are you using the same version of xjc
for B.xsd or a version newer than the one used on A.xsd?

If you are using the same version of xjc, then there is a chance you
might be able to merge things together from separate compilation steps.
If they are different versions, then I would say it probably isn't
possible. Your best bet is recompiling both schema at the same time
(see below).

> Say I have a utility library that uses XML schema A. My build runs xjc
> and puts everything into a jar. This jar is then used by a variety of
> applications.
>
> One application uses XML schema B, which imports schema A as a
> namespace. The problem is that when I run xjc over schema B, it goes and
> regenerates all the schema A bindings. I would like the generated schema
> B bindings to just reuse the schema A bindings that already exist.
>
> I tried using the same namespace and package names for the schema A
> stuff in both places, then ignoring the second lot of generated schema A
> bindings. It doesn't seem to work though. The Schema B bindings seem to
> be tied to the internals of the schema A bindings, so that they don't
> work with the classes in the utility jar.
>

This approach *might* work. Here is what I would try:

% xjc B.xsd -d gen-src -use-runtime org.acme.a.impl.runtime
% rm -rf gen-src/org/acme/a
% export CLASSPATH="A.jar:${CLASSPATH}"
% javac ...

As you stated above, you need to make sure that the code for A.xsd
is being generated into the same package in both invocations of xjc.

> Any suggestions on how to do this? All I've found is the advice
> "generate all your bindings in a single xjc invocation". That doesn't
> really work here, since I'm reusing a jar that has already been built.
>

This would be my recommendation. You should be able to regenerate
the bindings for A.xsd by compiling B.xsd without impacting your
existing client apps. Can you elaborate on why you think this won't
work?

> The brute force option is to put the schema A bindings in a different
> package on the second run. I duplicate a whole bunch of code, but it
> should work. The problem there is that any code written to use the
> bindings can't work with both versions. I'd have to duplicate that code
> too.
>

This sounds like the wrong approach.

Please report back and let everyone know how you solve this issue.

Thanks,

--Ryan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net