简体   繁体   中英

How to generate several versions of Java classes generated by JAXB?

I recently generate two versions of Java classes generated by JAXB. So I get two packages : V1_0 and V2_0

I notice that I have only one ObjectFactory generated. The problem is that this ObjectFactory is specific to a version (here it's specific to my version v1_0).

So the question is : Could I configure JAXB to allow to make one ObjectFactory for each version ?

Thanks a lot.

If the two versions of the API are in the same namespace, that's horrible! You'll have the object factory from one round of generation overwriting the object factory produced by the other (or inhibiting; I forget which xjc actually does). It's also horrible for clients of the API since they won't know what version of the API they're dealing with (unless you're doing other nasty tricks, which ought to be discouraged; if they're in the same namespace they should be the same API).

The fix is to put the two APIs in different namespaces so that they get generated into different packages with different object factories. (Also beware of any use of the -p option to xjc ; that can cause things to go into the same namespace and give you these overwriting headaches.)

One object factory for both versions? Not, it is not possible. You get two sets of classes in two packages - it is not possible that one object factory serves both of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM