How to write an Ant xml build file to Generate JAXB Code and Compile and Build it to a Jar

There is a pretty common situation to use a java classes generator and to create classes based on a defined pattern. Hibernate, Castor, Jaxb are a few examples. I prefer to have those classes packed in a separate jar file. Since they are generated files it’s not a good practice to modify them, so there is not need to have them in your project. Debugging is the case when you need the source of generated classes. In this case you can simply attach the jar containing sources in your IDE (eclipse supports it, I think other IDE support it either). Continue reading

JAXB Castor Comparison

I was looking recently for some java framework to save some objects in xml files. Until now I’ve tested from a noob perspective 2 frameworks: JAXB and Castor. Don’t get misleaded by my judgment because I didn’t use any of them very deep.

I was playing with JAXB some time ago and at that time I’ve seen some interesting features there. I’ve created an XSL schema file and I’ve then generated some files. The generated classes were not some simple POJO files. They contain some annotations specifying the names of the tag and attributes in the XML file. I know this technique from .NET, where I’ve used it for some time and I consider it great(but it comes with a big disadvantage – you can not use some existing classes unless you change them and add annotations).

JAXB is not a single framework, it is a part of the Sun JWSDP – Java Web Services Developer Pack (Java WSDP) 2.0
Continue reading