Search code examples
javajaxbauthzforce

Is it possible to explicitly point jaxb to its stubs


I have generated classes for a web service implementing the xacml specification model and having the following package: oasis.names.tc.xacml._3_0.core.schema.wd_17 (not a jaxb).

I also have an external library inside which jaxb-stabs are located along the same path - oasis.names.tc.xacml._3_0.core.schema.wd_17. The jaxb stubs are used to work with pdp-engine policies.

And when I call the pdp library i get an error:

javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 4 counts of IllegalAnnotationExceptions Two classes have the same XML type name "{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}anonimous". Use @XmlType.name and @XmlType.namespace to assign different names to them. this problem is related to the following location: at oasis.names.tc.xacml._3_0.core.schema.wd_17.DefaultsType$Anonimous at public oasis.names.tc.xacml._3_0.core.schema.wd_17.DefaultsType$Anonimous oasis.names.tc.xacml._3_0.core.schema.wd_17.DefaultsType.getAnonimous() at oasis.names.tc.xacml._3_0.core.schema.wd_17.DefaultsType at public oasis.names.tc.xacml._3_0.core.schema.wd_17.DefaultsType oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory.createDefaultsType() ...

Is there any way to avoid such a problem without renaming of packages path?


Solution

  • I tried to explicitly list all the necessary classes when creating a JAXBContext, index, put jaxb-stabs in the same library where they are needed, etc. After that I wrote my own classloader in which I redefined only what the library needs and launch the engine library with that, so jaxb still finds a duplicate that is not XMLType because it loads earlier than my service.

    The working solutions turned out to be using single stabs for both or renaming one of the packages so that there would be no conflict