The scenario is the following: I have a java package (myapp.config) that contains all my JAXB-annotated classes, from which I'd like to generate an XML schema file. In the package, there is also a package-info.java file, which contains the @XmlSchema annotation on the package element, thus valid in the whole package:
@XmlSchema(namespace="http://myapp/config",
xmlns = @XmlNs(prefix="myapp", namespaceURI="http://myapp/config"),
elementFormDefault=XmlNsForm.QUALIFIED)
package myapp.config;
When I run the schemagen command-line tool that comes with the JDK,
D:\Projects\Myapp>"%JAVA_HOME%/bin/schemagen" -cp "%JAVA_HOME%/lib/tools.jar"
src/myapp/config/*.java
I get the correct result: the root element in the generated schema1.xsd file contains the targetNamespace and other necessary attributes:
<xs:schema elementFormDefault="qualified" version="1.0"
targetNamespace="http://myapp/config"
xmlns:tns="http://myapp/config"
xmlns:myapp="http://myapp/config">
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
However, when I want to perform the same task within my Ant script,
<schemagen srcdir="src/myapp/config" destdir="dist">
<include name="*.java"/>
</schemagen>
The schemagen tool seems to completely ignore the namespace annotations, because in the resulting schema1.xsd file, there is no trace of them:
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
When I run the schemagen task in verbose and debug mode, it becomes obvious that the tool does load all the .java files, except package-info.java, that's why it doesn't know anything about the namespaces.
Have you met this strange behavior before? Why the command-line tool processes the package info file, and the Ant task doesn't? What should I do to make the Ant task work?
Thanks in advance,
buc