Java: Deprecated JAXB in JAva 9+. Using JAXB with DOCX4J to bind XML data with a MS Word template. Anyone know of an alternative in Java 9+

huangapple go评论82阅读模式
英文:

Java: Deprecated JAXB in JAva 9+. Using JAXB with DOCX4J to bind XML data with a MS Word template. Anyone know of an alternative in Java 9+

问题

我继承了一些Java代码,用于从XML文件获取数据并将数据插入Microsoft Word文档中。Java代码使用两个文件作为输入。一个是包含数据的XML文件,另一个是Microsoft Word文档,它被用作输出文件的模板。Word模板具有与XML文件中的XML标签相映射的内容控制对象。当执行Java程序时,它使用Word模板和XML文件,通过Word模板中的XML映射将这两个文件进行“绑定”。代码的输出是一个Word文档,其格式符合模板,但包含来自XML文件的更新数据。
绑定操作来自于DOCX4J库,具体是“Docx4J.bind()”方法。该方法使用了一个名为Javax.xml.bind.JAXBContext的jar包中的JAXB.Content。问题在于JAXB库和方法在Java 9及以后的版本中已被弃用并完全移除。因此,似乎让这个绑定方法工作的唯一方法是保持在Java 8版本中。我被要求寻找替代JAXB.Context的方法,以便Java代码可以在Java 13环境中编译和运行。
我的问题是:
在Java 11、12或13中,是否有类似的替代品来取代JAXB?如果有,是否可以指引我查阅相关文档以了解更多信息。
感谢您的参与和帮助。

英文:

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

JAXB不再在最近的JDK中提供,但JAXB本身仍然可以在参考实现和MOXy中轻松获得。JAXB没有被弃用。

请访问https://www.docx4java.org/downloads.html

如网页上所示,只需添加docx4j-JAXB-ReferenceImpl或docx4j-JAXB-MOXy中的一个即可。(只有docx4j-JAXB-Internal无法在您关注的Java版本上工作)

您可以使用8.x系列或11.x系列。8.x系列适用于Java 8,而11.x系列适用于Java 11+并包括module-info。

无论哪个版本都可以在Java 13上运行(至少适用于docx4j 8的类路径)。目前来看,8.x系列往往会首先获得新功能。

因此,总之,在Java 13上运行Docx4J.bind时不应遇到任何问题!

英文:

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!

huangapple
  • 本文由 发表于 2020年8月28日 06:22:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63624908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定