JAXB 在 Java 5 下工作吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2895777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 23:19:43  来源:igfitidea点击:

Does JAXB work under Java 5?

javajaxb

提问by Arne Evertsson

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

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

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

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

回答by Rakesh Venkat

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

JAXB API 捆绑在 JDK1.6 中,但这些在 JDK <1.6(例如: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:

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

*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 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.

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

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

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

回答by skaffman

You can download the reference implementation (RI) from http://jaxb.dev.java.net/.

您可以从http://jaxb.dev.java.net/下载参考实现 (RI) 。

I can't advise you on how to make it work with maven though - more trouble than it's worth, if you ask me.

我不能就如何让它与 maven 一起工作向你提供建议——如果你问我的话,麻烦多过它的价值。

Java6 included a slightly modified version of the RI, but the RI itself works just fine with Java5.

Java6 包含一个稍微修改过的 RI 版本,但 RI 本身与 Java5 一起工作得很好。

回答by Geoff

It seems there are many versions and differing paths to get JAXB from a maven repository.

似乎有许多版本和不同的路径可以从 Maven 存储库中获取 JAXB。

My best guess for the correct artifact is javax.xml.bind:jaxb-api:2.2

我对正确工件的最佳猜测是 javax.xml.bind:jaxb-api:2.2

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2</version>
    <scope>compile</scope>
</dependency>

回答by M-Zaiady

Using the following versions will work with JDK5:

使用以下版本将适用于 JDK5:

      <!-- 
              versions after 2.2.4 requires jdk6, please refer 
             to https://java.net/jira/browse/JAXB-890 
       -->

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.4-1</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.4</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.soap</groupId>
        <artifactId>saaj-api</artifactId>
        <version>1.3.3</version>
    </dependency>

回答by jakob

Jaxb should work with Java 5 but it seems that there are more people having issues with it. Could it be that are missing some jars?

Jaxb 应该与 Java 5 一起使用,但似乎有更多人遇到问题。可能是缺少一些罐子吗?

Check out thisforum post.

看看这个论坛帖子。