Tâche Schemagen Ant ignore le paquet-info.java
Question
Le scénario est ce qui suit: j'ai un package Java ( myapp.config ) contenant toutes mes classes JAXB-annotées, à partir desquelles je voudrais générer un fichier de schéma XML. Dans le paquet, il existe également un fichier package-info.java , qui contient l'annotation @xmlschema sur l'élément de package, ainsi valide dans l'ensemble du package:
@XmlSchema(namespace="http://myapp/config",
xmlns = @XmlNs(prefix="myapp", namespaceURI="http://myapp/config"),
elementFormDefault=XmlNsForm.QUALIFIED)
package myapp.config;
Lorsque j'exécute l'outil de ligne skemagen schemagen avec le JDK,
D:\Projects\Myapp>"%JAVA_HOME%/bin/schemagen" -cp "%JAVA_HOME%/lib/tools.jar"
src/myapp/config/*.java
Je reçois le résultat correct: l'élément racine du fichier généré schema1.xsd contient le cibleNamespace et d'autres attributs nécessaires:
<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" >
Cependant, lorsque je veux effectuer la même tâche dans mon script d'ant,
<schemagen srcdir="src/myapp/config" destdir="dist">
<include name="*.java"/>
</schemagen>
L'outil Schemagen semble ignorer complètement les annotations d'espace de noms, car dans le fichier schema1.xsd résultant, il n'y a aucune trace d'eux:
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
Lorsque j'exécute la tâche schemagen dans verbose et le mode de débogage , il devient évident que l'outil charge tous les . Java fichiers, sauf package-info.java , c'est pourquoi il ne sait rien des espaces de noms.
Avez-vous déjà rencontré cet étrange comportement? Pourquoi l'outil de ligne de commande traite-t-il le fichier d'informations d'emballage et la tâche ant ne le fait pas? Que dois-je faire pour faire fonctionner la tâche ant?
Merci d'avance,
BUC
La solution
Fortunately I found the solution, I post it for those who run into the same problem in the future:
The reason it did not work is that I called the schemagen task in the wrong way (this can happen, if there is so little documentation or examples as in the case of schemagen). Instead of writing:
<schemagen srcdir="src/myapp/config" destdir="dist">
<include name="*.java"/>
</schemagen>
You should move the specific part of the path into the include element:
<schemagen srcdir="src" destdir="dist">
<include name="myapp/config/*.java"/>
</schemagen>
I'm still not sure why this is happening, but this way, the schemagen processor recognizes that the myapp/config directory in fact designates the java package myapp.config and by knowing that it is a package, it will also read the package info file.