문제

시나리오는 다음과 같습니다. 나는 XML 스키마 파일을 생성하려는 모든 JAXB 주석이있는 클래스를 포함하는 Java 패키지 ( myApp.config )가 있습니다. 패키지에서 패키지 요소에 @xmlschema 주석을 포함하는 package-info.java 파일이 있습니다. 따라서 전체 패키지에서 유효합니다. schemagen 명령 줄 도구가 JDK와 함께 제공되는

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>
.

결과 schema1.xsd 파일에서 파일이 없으므로 schemagen 도구는 이름 공간 주석을 완전히 무시하는 것으로 보입니다.

<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
.

verbose 디버그 모드에서 schemagen 태스크를 실행하면 도구가 모든 을로드하는 것이 분명해진다. Java 파일은 package-info.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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top