JAXB 在 Java 5 下工作吗?

2022-01-19 00:00:00 java jaxb

使用 maven 构建我得到包 javax.xml.bind.annotation 不存在"

Building with maven I get "package javax.xml.bind.annotation does not exist"

我需要什么才能使 JAXB 与 Java 5 一起使用?

What do I need to make JAXB work with Java 5?

推荐答案

JAXB API 捆绑在 JDK1.6 中,但在 JDK <1.6(例如:JDK1.5)中不可用.

JAXB APIs are bundled in JDK1.6, but these are not available in JDK <1.6 (ex: JDK1.5).

我有一个用 JDK1.6 编写的 Java 到 XML 代码,一旦我切换到 JDK1.5,我得到以下错误:

I have a Java to XML code written in JDK1.6 and once I switched to JDK1.5, I got the following error:

*Exception in thread "main" java.lang.RuntimeException: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
...
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]*
...

JDK1.5 不包含 JAXB API,因此我应用了以下修复:我在类路径中使用了JDK1.5和以下两个JARS:jaxb-api-2.0.jar和jaxb-impl-2.0.jar,错误已解决.

JDK1.5 doesnt contain the JAXB APIs and therefore I applied the following fix: I used JDK1.5 and the following two JARS: jaxb-api-2.0.jar and jaxb-impl-2.0.jar in my classpath and the error was resolved.

我希望这会有所帮助.另一个参考:http://www.mkyong.com/java/jaxb-hello-world-example/

I hope this helps. Another Reference: http://www.mkyong.com/java/jaxb-hello-world-example/

相关文章