Question

On my current project we generate JAXB beans from an XSD file. We need line number information on the beans (beyond XSD validation errors!) so I used the -Xlocator option specified here:

http://java.sun.com/webservices/docs/1.6/jaxb/xjc.html

However, I'm missing the Locator class. The jar file referenced to on that six-year old page can't be found anywhere, as I don't see a download for JWSDP on any site at all.

Is XJC dead? Should I be using something else?

Edit: solution has to use Java 1.5

Was it helpful?

Solution 3

I found the problem, or at least part of it. XJC generates imports to the "internal" package versions of XmlLocation and Locatable. Don't ask me why!

I wrote a little script to replace these imports with the correct ones, and it seems to work fine now.

OTHER TIPS

XJC is far from dead, but that page you're referencing is ancient, and applies to JAXB 1. Java6 contains JAXB 2.1 (see the docs here). It's annoying that when you do a google search today, most of the hits you get back are for obsolete JAXB 1 references.

I'm not sure what you're requirements are. What do you mean by "We need line number information on the beans"?

edit: You mentioned the @XmlLocation annotation. This is a non-standard annotation within both Java6 and the JAXB reference implementation, which you'll be using with Java5. The classname is com.sun.xml.bind.annotation.XmlLocation, and the javadoc is here. The reference implementation you can get from here, if you don't have it already.

Thank you. I downloaded the jaxb-impl.jar since the the jaxb-api.jar is already included in Java 6 API. Just in case someone else needs a linux script to replace the wrong imports, as mentioned by Wouter.

Navigate to your project path and adjust com.abc.generated and abc.xsd.

#!/bin/sh
xjc -d src/ -p com.abc.generated -Xlocator abc.xsd

FILES=$(find src/ -type f -name *.java)
for f in $FILES
do
    sed -i 's/\(.*import com.sun.xml.internal.bind.Locatable;.*\)/import com.sun.xml.bind.Locatable;/g' $f
    sed -i 's/\(.*import com.sun.xml.internal.bind.annotation.XmlLocation;.*\)/import com.sun.xml.bind.annotation.XmlLocation;/g' $f
done

For Maven-User add the dependency

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

and replace the imports

import com.sun.xml.internal.bind.Locatable;
import com.sun.xml.internal.bind.annotation.XmlLocation;

with

import com.sun.xml.bind.Locatable;
import com.sun.xml.bind.annotation.XmlLocation;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top