Building with maven I get "pack开发者_开发技巧age javax.xml.bind.annotation does not exist"
What do I need to make JAXB work with Java 5?
JAXB APIs are bundled in JDK1.6, but these are not available in JDK <1.6 (ex: 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 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.
I hope this helps. Another Reference: http://www.mkyong.com/java/jaxb-hello-world-example/
You can download the reference implementation (RI) from http://jaxb.dev.java.net/.
I can't advise you on how to make it work with maven though - more trouble than it's worth, if you ask me.
Java6 included a slightly modified version of the RI, but the RI itself works just fine with Java5.
Using the following versions will work with 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>
It seems there are many versions and differing paths to get JAXB from a maven repository.
My best guess for the correct artifact is 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>
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?
Check out this forum post.
精彩评论