I have found that JAXB by itself is not creating the XML schemas. However, they are needed to be consumed by JAXB. XML schemas are essential for JAXB to function (i.e. I haven’t seen a tutorial that is based only on a Java Class; every tutorial is discussing how an XML schema is being created, after parsing a specific Class.)
I also have found that within JAXB, there is a part (package or class) called schemagen that is responsible for creating the XML schemas. I think this class should be used to generate the default XML schema and then use JAXB.
Note 1: It sounds like I need to create the Schema and then use the marshalling on the Class. The only thing remaining is the values of the elements in XML; I don’t want to marshal the class but the object of it.
Note 2 : The class is needed to be mapped to the XML schema so that the object can be marshallized.
Schemagen can be located at C:Program FilesJavajdk1.6.0_21bin. It is an .exe file. Thus, it would not be easy to be used within a java program.
In here it has been said that:
The jaxb-xjc.jar file contains the SchemaGenTask.class file, which allows the schema generator to be invoked from the Ant build tool.
It seems that you need to have your packages annotated in order for JAXB to be able to create schema on that. This is writing from Alex Miler that describes this annotation. This and this is the annotation specification for packages in Java Documents. In these definitions you can not find various package annotation elements to be used, it simply defines what a package annotation is.
Annotations may be used on package declarations, with the restriction that at most one annotated package declaration is permitted for a given package.
One other possible way to use the JAXB is to have a file called jaxb.index in your class path. Not sure yet what that file is and how is working.
Problem solution found:
You need to have a class passed to the newInstance(), you can simply get the class you need to marshalize using the .getClass function.
JAXBContext jContext = JAXBContext.newInstance (this.getClass ());