0
votes

I inherited some Java code that gets data from an XML file and inserts the data into Microsoft Word document. The Java code uses two files as input. One is the XML file with data and the other is a Microsoft Word Document which is used as a template for the output file. The Word template has Content Control objects which are mapped to XML tags from the XML file. When the Java program is executed, it uses the Word template and the XML file to "bind" the two files together using the XML mappings in the Word template. The output from the code is a Word document in the format of the template, but with updated data from the XML file.
The binding is from the DOCX4J Library namely "Docx4J.bind()". This method uses JAXB.Content from a jar named Javax.xml.bind.JAXBContext. The problem is the JAXB library and methods are all deprecated and completely removed from Java 9 and forward. So it appears the only way to make this bind method work is to stay in Java version 8. I have been asked to find an alternative to JAXB.Context so that the Java code can be compiled and run in a Java 13 environment.

My question is this: Is there a comparable replacement for JAXB in Java 11,12 or 13? If so, can you please point me to some documentation to find out more about it. Thanx for your input and help.

1

1 Answers

1
votes

JAXB is no longer shipped in recent JDKs, but JAXB itself is still readily available, in the reference implementation, and in MOXy. JAXB is not deprecated.

Have a look at https://www.docx4java.org/downloads.html

As it says there, just add ONE only of docx4j-JAXB-ReferenceImpl or docx4j-JAXB-MOXy. (It is only docx4j-JAXB-Internal which won't work on the versions of Java of interest to you)

You can use either the 8.x series or the 11.x series. The 8.x series is compiled for Java 8, whereas the 11.x series is compiled for Java 11+ and includes module-info.

Either will work on Java 13 (for docx4j 8, the class path at least). At present, the 8.x series tends to get new features first.

So, in summary, you should not encounter any problems at all running Docx4J.bind on Java 13!