Categories
Articles

JAXB – XJC Plugin (Inherit class for specific element)

I was working on one of the project, wherein I needed an extension in JAXB to inherit class for a specific element defined in XSD. After googling through some sites, I found JAXB – superClass. But the problem of using this extension is that it makes all the classes in given XSD to inherit the declared superClass. The solution to above problem is to create separate XSD – specifically for the given element and achieve inheritance. Ahhhh! not feasible for me.
So the alternate solution was to build one rather than spending time in finding. Alas after spending few minutes, I could build one and it is working as expected.
To use this Plug-in, refer following example



	
		
			MyElementBaseClass
		
	


Add following argument to XJC compiler -Xextends
You can download the JAR by clicking here(Due to security reasons, I had to rename the JAR to ZIP). The JAR contains source code as well. You can go through the source code to understand how it is developed.