Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>XJC-generated Java source files use annotations from the JAXB API. In order to compile them, those annotation types must be on the classpath.</p> <p>To use JAXB (for marshalling and unmarshalling to/from XML documents) you'll need these things:</p> <ul> <li>The JAXB API definitions.</li> <li>A JAXB implementation.</li> <li>Any libraries the implementation depends on.</li> </ul> <p>An implementation is separate from the API and interchangeable. It will be located via the Java service provider mechanism. I won't go into the details of that here, but let's say it should be sufficient to have a jar with an implementation on your classpath. Normally you'll only make calls to the JAXB API classes. For example, <code>JAXBContext.newInstance("my.sample.pack");</code>.</p> <p>The actual implementation is located at runtime and loaded through your API calls. This means that in order to compile JAXB code, a jar with the API should suffice. An implementation and its dependencies is only required at runtime.</p> <p>Now for a JDK 1.6.x, you won't need to include anything additional on your classpath. Starting with Java SE 6, the JAXB API was included in the standard Java SE API. The Java Runtime Environment also includes an implementation of that API. This is the Reference Implementation available on <a href="http://jaxb.java.net/" rel="nofollow">the java.net JAXB site.</a></p> <p>For JDK 1.5.x, things are a bit different. The JAXB API was not yet included as a standard Java API. So you'll need to make it available manually. At the very least you'll need the API; the implementation you're going to use is free to choose, although I don't know any besides the reference implementation from the top of my head. It is probably the best one to start with. Click the "download now" button on the JAXB site linked above. You'll see a link to download a jar file. Get that and open it either by double-clicking it in your file system or running it via the command line. This will extract some content to a folder in the same location as the jar. You'll see a number of folders. The bin folder contains runnables for xjc and schemagen. There's also documentation and sample folders. The lib folder is the one interesting to us. Here's a rundown:</p> <ul> <li>jaxb-api.jar: this is the JAXB API; you'll need this for compiling your generated code</li> <li>jaxb-impl.jar: the reference implementation; not needed for compiling but you'll want this at runtime</li> <li>jaxb-xjc.jar: useful for invoking xjc programmatically or in Ant</li> <li>jaxb1-impl.jar: the reference implementation of the JAXB 1 API; I assume you'll stick to JAXB 2 so ignore it</li> <li>activation.jar: a dependency, not needed for compiling but might be needed at runtime</li> <li>jsr173_1.0_api.jar: this is in fact the Java Streaming API for XML (StAX); it is used by the JAXB reference implementation</li> </ul> <p>That last one works like JAXB in terms of implementation. It is an API with interchangeable implementations. And just like JAXB, it's not available by default in Java 5 but was included in the Java 6 API. You'll probably need an implementation for this as well in Java 5. I leave you to find and use it; the steps followed will closely ressemble what I described for JAXB.</p> <p>So, to wrap it all up in a concise overview... If you can use Java 6, pretty much all dependencies are available out of the box and you won't need any additional stuff on your classpath to compile JAXB-related code and run it. For Java 5, you'll at least need the JAXB API for compilation and the API plus an implementation at runtime. The implementation might have some dependencies of its own, so if you're still getting ClassNotFound errors, try to find out what project the missing class is a part from.</p> <p>The jarfinder site suggested by Pangea can be very useful for this. But don't skip the step of checking the actual project site to make sure you get all dependencies, the latest version and see what the licensing terms are.</p> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload