I have this test class
import javax.xml.bind.annotation.XmlElement;
class CompileTest {
void foo( @XmlElement String in ) {
}
}
my java version is
$ java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)
and when I try to compile that class I'm getting
javac CompileTest.java
CompileTest.java:5: annotation type not applicable to this kind of declaration
void foo( @XmlElement String in ) {
^
1 error
and that's valid for Java 6. When I tried to add newer JAXB library to class path, it didn't help. Is there a way to solve this?
javac -cp jaxb-api-2.2.4.jar CompileTest.java
XOM, JDOM, dom4j, etc. etc. Projects like Castor and Apache XMLBeans predate JAXB, so you could have a look at those. Ulf Dittmer wrote: XOM, JDOM, dom4j, etc.
1. 2.4. 0-* (under development)
Using the xjb and schemagen tools on JDK 11 The JAXB-specific xjc and schemagen tools, which you use to convert an XML Schema (*. xsd file) to a set of Java classes and vice versa, are included with the JDK up to version 10, but have been removed in JDK 11.
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.
Use the Java Endorsed Standards Override Mechanism
Put your jaxb-api-2.2.4.jar
inside <java-home>\lib\endorsed
directory.
Or, use the -D java.endorsed.dirs option
javac -Djava.endorsed.dirs=/your/path/to/jaxb-directory CompileTest.java
References:
http://docs.oracle.com/javase/6/docs/technotes/guides/standards/
Use the concept of "endorsed libraries" folder. Take a look here: How can I make Ant use JAXB x instead of Java 6 SE JAXB classes ...
Basically this is a way to instruct the JRE to use a more recent version of JAXB.
You can read more here: Unofficial guide to JAXB: Using JAXB 2 with SE 6 Also see this question: What is the exact way to use endorsed directory in JRE 6
It can only be applied at field or method, not on method parameter. See
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlElement {
Edit: Source of XmlElement (JDK 1.6.0_18)
* @since JAXB2.0
* @version $Revision: 1.19 $
*/
@Retention(RUNTIME) @Target({FIELD, METHOD})
public @interface XmlElement {
So what I see is 1.6.0_18 version has XmlElement of 1.19 revision having only FIELD
and METHOD
target available.
Edit: So your problem is jdk 1.6 XmlElement isn't same as jaxb.2.2. you can check source at http://grepcode.com/file/repo1.maven.org/maven2/javax.xml.bind/jaxb-api/2.2.4/javax/xml/bind/annotation/XmlElement.java?av=f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With