Repository navigation
Description
Hey there.
My usage of jaxb-tools
I'm using jaxb-tools in a factur-x API for :
- Generating classes from
xsdfiles usingxjcand your maven plugin - Mapping appropriate namespaces to the XML tags when marshalling my object into a
xmlstring
Context
Basically, my process involves :
- Sending a
jsonfile with the appropriate serialized object along with a pdf - The
jsonis mapped into an object from the jaxb-generated classes - I then marshal this object into a proper
xmlfile with the correct namespaces - I incorporate the
xmlinto thepdfto create a factur-x file
My issue
My issue is related to namespaces associations in the package-info file.
I don't understand why my generated package-info would be different if my executions in the pom.xml file are identical, same thing for the bindings.xjb files. But here they are :
Hence, the minimal profile is working fine with proper generation of factur-x compliant file.
The 4 other profiles don't work well at all.
Reproducible example
Here is my plugin config inside my pom.xml :
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>4.0.8</version>
<configuration>
<extension>true</extension>
<args>
<arg>-Xnamespace-prefix</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
<version>4.0.8</version>
</plugin>
</plugins>
</configuration>
<executions>
<execution>
<id>xjc-minimum</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/minimum</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-sources/jaxb/minimum</generateDirectory>
<generatePackage>REDACTED.entity.generated.minimum</generatePackage>
<cleanPackageDirectories>false</cleanPackageDirectories>
</configuration>
</execution>
<execution>
<id>xjc-basicwl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/basicwl</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-sources/jaxb/basicwl</generateDirectory>
<generatePackage>REDACTED.entity.generated.basicwl</generatePackage>
</configuration>
</execution>
<execution>
<id>xjc-basic</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/basic</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-sources/jaxb/basic</generateDirectory>
<generatePackage>REDACTED.entity.generated.basic</generatePackage>
</configuration>
</execution>
<execution>
<id>xjc-en16931</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/en16931</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-sources/jaxb/en16931</generateDirectory>
<generatePackage>REDACTED.entity.generated.en16931</generatePackage>
</configuration>
</execution>
<execution>
<id>xjc-extended</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schemas/extended</schemaDirectory>
<generateDirectory>${project.build.directory}/generated-sources/jaxb/extended</generateDirectory>
<generatePackage>REDACTED.entity.generated.extended</generatePackage>
</configuration>
</execution>
</executions>
</plugin>Here you can find the approporiate filestructure using the xsd files from fnfe-mpe.org zip :
And finally, here is a bindings.xjb file example, only the schemaLocation is changing :
<?xml version="1.0"?>
<jxb:bindings xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:namespace="urn:jaxb.jvnet.org:plugin:namespace-prefix"
version="3.0">
<jxb:globalBindings>
<xjc:simple/>
</jxb:globalBindings>
<jxb:bindings schemaLocation="Factur-X_1.0.07_MINIMUM.xsd">
<jxb:schemaBindings>
<jxb:package name="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"/>
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="rsm"/>
<namespace:prefix name="ram" namespaceURI="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"/>
<namespace:prefix name="udt" namespaceURI="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"/>
<namespace:prefix name="qdt" namespaceURI="urn:un:unece:uncefact:data:standard:QualifiedDataType:100"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>Note that the globalBindings part is used for defining the XmlRootElement that would otherwise be missing when marshalling to xml :
jakarta.xml.bind.MarshalException<EOL> - with linked exception:<EOL>[com.sun.istack.SAXException2: unable to marshal type "REDACTED.entity.generated.extended.CrossIndustryInvoiceType" as an element because it is missing an @XmlRootElement annotationQuestions
- Is there anything I'm doing that is wrong ? I have read extensively your documentation and stack overflow posts, but I might have missed something
- Otherwise, maybe something is wrong in the librairy handling of multiple executions. Maybe I can help finding a fix ?
Thanks in advance and have a great day !


Activity
laurentschoelens commentedon Nov 22, 2024
Hi @mathisgauthey
Thanks for your detailed issue.
We'll check soon if it is a bug or a configuration problem.
Regards
laurentschoelens commentedon Nov 25, 2024
Hi @mathisgauthey : you're mentionning "fnfe-mpe.org zip" but I can't find the mentionned zip file above. Could you share it please as MRE ?
Thanks 😄
mathisgauthey commentedon Nov 25, 2024
Hey there, I just downloaded it in french and remove the unwanted files so that it fits the 25mo Github limit.
You'll find
xsdfiles along with factur-x PDF examples.factur-x.zip
mathisgauthey commentedon Nov 25, 2024
I happened to find a workaround that could help locate the problem.
Removing this part from the binding files :
It allows me to use
CrossIndustryInvoiceType.javainstead ofCrossIndustryInvoice.javaand it removed the unusual duplicated package-info :And then, the only issue I had left was related to using an Object of
CrossIndustryInvoiceType: There was an error with amissing @XmlRootElementwhich I solved by marshalling differently :Old :
New :
It now works fine, I needed to modify some of my jsons input files because removing the part from the bindings file renamed some attributes from plural to strictly singular. But it now works fine !
laurentschoelens commentedon Nov 25, 2024
That's good news 😄
You can manually add the
@XmlRootElementto theCrossIndustryInvoiceTypeby using thejaxb-annotate-pluginwith appropriate binding file.