Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does JAXB work under Java 5?

Tags:

java

jaxb

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

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

like image 540
Arne Evertsson Avatar asked May 24 '10 08:05

Arne Evertsson


People also ask

Is JAXB still supported?

As of Java 11, JAXB is not part of the JRE anymore and you need to configure the relevant libraries via your dependency management system, for example Maven or Gradle. This tutorial demonstrates both approaches. The JAXB reference implementation is developed on Github Jaxb api project page.

Is JAXB included in JDK?

JAXB was integrated within the JVM itself, so you didn't need to add any code dependency to have the functionality within your application. But with the modularization performed in JDK 9, it was removed as the maintainers wanted to have a smaller JDK distribution that only contains the core concepts.

What version of JAXB is in Java 8?

1. 2.4. 0-* (under development)

Is JAXB obsolete?

Since JAXB has been completely removed from Java SE 11, the xjc and schemagen tools are also no longer available.


2 Answers

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/

like image 149
Rakesh Venkat Avatar answered Oct 22 '22 01:10

Rakesh Venkat


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.

like image 32
skaffman Avatar answered Oct 22 '22 00:10

skaffman