"What if? Why not? Challenge the Convention! Let's do some incredible things!"  More Quotes

Welcome to Aspire Knowledge Central (AKC)

   Home   Public Library   Author Content

Choose a data format:   classic-xml   object-xml   embedded-xml   text   excel

Jaxb 2.0 tutorial

Goal

  1. Realize the reflection based architecture of Jaxb
  2. Plan a sample project for exercising Jaxb
  3. Prerequisites
  4. Resources and how best to use them

Reflection based architecture

jaxb 2.x architecture supports metadata based marshalling and unmarshalling of xml. This makes xsd optional unlike the jaxb 1.x architecture

Tutorial Project

The project is a simple project where an xml file is marshalled and unmarshalled using jaxb 2.x. All of the files needed to accomplish this are provided on the right hand side of the menu.

Prerequisites

Because jaxb 2.x relies on reflection, you will need to get jdk 1.5. And also a development environment that works with jdk 1.5. See the pre-requisites menus on the right hand side to get some help on these pre-requisites. I have used the 3.1 release candidate of eclipse to work with jdk 1.5. Seem to work ok

You will also probably need to understand XSDs if you are planning on exploring options with XSDs.

Some tool like XML SPy might be helpful although not required. In the XSD links I have put a link for online xsd verifiers

How best to use the tutorial page

Using the the notes on eclipse, you may want to download and install 1.5 development environment. You will also want to read up briefly on what metadata is and how to use it to annotate your code.

The key to using jaxb 2.x effectively is to understand the metadata attributes. You can look these up in the jaxb java api. Sometimes the java api description is a bit terse. The best place to look up is the jaxb mailing list. For convenience I have placed a search link for the news groups.

While working with the tutorial you will also need java api links for jaxb and jdk. I have placed these links as well on the control pages.

In short everything you need to work with this tutorial is included in the links here. Just keep this browser page open in the background when you are developing your tutorial and you will have everything you need in one place.

Check my working notes

I have a running notes that I have kept track of while I have developed and tested the solution. Use this link to read through to see if you run into similar things. You can use the feedback links, if you want to add your own things to it.

Bonus

I have included a section called "Rolling your own reflection". You are probably thinking why is this needed when I have so many tools that I can between xml and java. These classes goes to the core idea of how most of these tools work. Knowing that you can use the concept in a number of scenarios, including rolling your own jaxb 2.x like package to run on java 1.4.x. Why is that important, well a number of IT companies may take a while to go to jdk 1.5, rendering that option quite impractical. Under such cases you have the option of using Castor or something like this. The advantage of using this option, is your entire code is packaged as a jar file and no additional configuration files. You can also use this technology for mapping partial xml to java or binding non xml data to java.