Open umefjord opened 5 years ago
Not sure I agree with this conclusion, "user error." The plugin does not correctly handle integration with the package-info.java to set a unique prefix and namespace. You can set the namespace via package-info but not the prefix. The result is you are forced to use the dreaded NamespacePrefixMapper in your jaxb marshaller. Hopefully, umefjord's commit would fix this; if it did, it would be a nice addition to this plugin.
Re-posting the same problem as mentioned in https://github.com/mojohaus/jaxb2-maven-plugin/issues/52, with a new description and motivation:
We specify explicit xmlns namespace prefixes in our package-info.java files, in order to get well-defined namespace-prefixes in the generated XML.
Example package-info.java:
We want the same well-defined namespaces in the XSD:s that are generated with the schemagen mojo, so we configure the mojo with:
However, the mojo fails when the namespaces are specified in the package-info.java files, with the following error:
The problem seems to be related to the "tns" namespace prefix that is used by the mojo prior to the transform schema post-processing phase. As mentioned above we want to replace this with something unique and well-defined.
If we remove the xmlns-part in the package-info.java file we don't get predefined namespace prefixes in the generated XML, and if we remote the-part of the -tags we don't get the predefined prefixes in the schemagen generated XSD. Hence none of that is acceptable.
However, by a couple of small modifications to the mojo we can fix the problem:
SimpleNamespaceResolver.java#214
XsdGeneratorHelper.java#490
This fix does the trick for us, hopefully it can make it into an upcoming official version as well.
Tested with jaxb2-maven-plugin, version 2.5.0.