Schemagen Antタスクはpackage-info.javaを無視します
質問
シナリオは次のとおりです。私はすべての私のJAXB注釈付きクラスを含むJavaパッケージ( myapp.config )があります。そこからXMLスキーマファイルを生成したいと思います。パッケージ内には、 package-info.java ファイルがあります。これには、パッケージ要素上の @xmlschema 注釈が含まれているため、パッケージ全体で有効です。
.
@XmlSchema(namespace="http://myapp/config",
xmlns = @XmlNs(prefix="myapp", namespaceURI="http://myapp/config"),
elementFormDefault=XmlNsForm.QUALIFIED)
package myapp.config;
JDKに付属の schemagen コマンドラインツールを実行すると、
.
D:\Projects\Myapp>"%JAVA_HOME%/bin/schemagen" -cp "%JAVA_HOME%/lib/tools.jar"
src/myapp/config/*.java
正しい結果を得ます:生成された schema1.xsd ファイル内のルート要素には、 targetnamespace およびその他の必要な属性が含まれています:
.
<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" >
しかし、私のAntスクリプト内で同じタスクを実行したい場合は、
.
<schemagen srcdir="src/myapp/config" destdir="dist">
<include name="*.java"/>
</schemagen>
Schemagenツールは、結果として生じる schema1.xsd ファイルでは、それらのトレースがないため、名前空間の注釈を完全に無視しているようです。
.
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
verbose および debug モードで schemagen タスクを実行すると、ツールがすべてのをロードすることが明らかになります。 package-info.java を除くjava ファイルは、ネームスペースについては何もわからない理由です。
前にこの奇妙な行動を満たしましたか?コマンドラインツールがパッケージ情報ファイルを処理し、Antタスクはなぜなのか。アリのタスクが作業するために何をすべきですか?
事前にありがとう、
BUC
解決
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.