[英]Error in jaxb2-maven-plugin XJB: The namespace of element 'bindings' must be from the schema namespace'
[英]Using XJB with jaxb2-maven-plugin
我有一個多模塊maven項目,結構如下:
root-module
|__module-a
| |__src
| |__main
| |__xsd
| | |__my.xsd
| |__xjb
| |__my.xjb
|__module-b
根模塊的POM只是聚合模塊a和b(以及其他內容):
<project>
<artifactId>root-module</artifactId>
<packaging>pom</packaging>
<modules>
<module>module-a</module>
<module>module-b</module>
</modules>
</project>
模塊a的POM如下(除其他外):
<project>
<parent>
<artifactId>root-module</artifactId>
</parent>
<artifactId>module-a</artifactId>
<properties>
<my-definitions.xsd>${basedir}/src/main/xsd/my.xsd</my-definitions.xsd>
<my-bindings.xjb>${basedir}/src/main/xjb/my.xjb</my-bindings.xjb>
<my.output>${basedir}/target/generated-sources/jaxb/my</my.output>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-my-classes</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<sources><source>${my-definitions.xsd}</source></sources>
<xjbSources><xjbSource>${my-bindings.xjb}</xjbSource></xjbSources>
<outputDirectory>${my.output}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
因此,當我在module-a運行mvn時,一切正常,構建成功。 但是當我在root-module上運行它時,我從XJC插件中獲取異常,它試圖在根模塊下找到綁定文件:
com.sun.istack.SAXParseException2; IOException thrown when processing "file:/home/root-module/src/main/xjb/my.xjb". Exception: java.io.FileNotFoundException: /home/root-module/src/main/xjb/my.xjb (The system cannot find the path specified).
有趣的是,它能夠正確定位XSD:
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc (generate-my-classe) on project module-a:
[ERROR] +=================== [XJC Error]
[ERROR] |
[ERROR] | 0: file:/home/root-module/module-a/src/main/xsd/my.xsd
[ERROR] |
[ERROR] +=================== [End XJC Error]
我的構建系統的細節:
Using Maven 3.2.5
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.1</version>
從這里引用JAXB2 Maven插件文檔。 還搜索了關於SO的一些相關問題,但他們沒有在任何地方解釋我的具體問題。
更新:看起來像一個懸而未決的問題 。 保持線程打開以防萬一有解決方法。
更新到插件的2.2版似乎工作。
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
使用插件的2.1版時我遇到了同樣的問題。 只需更改到2.2版即可解決問題。
在插件解析可用之前,我使用以下ant-run hack:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-my-classes</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<mkdir dir="${project.build.directory}/generated-sources/jaxb/my" />
<exec executable="${env.JAVA_HOME}/bin/xjc.exe" dir="${project.basedir}/src/main/xsd">
<arg value="-p" />
<arg value="my.package" />
<arg value="-b" />
<arg value="${project.basedir}/src/main/xjb" />
<arg value="-d" />
<arg value="${project.build.directory}/generated-sources/jaxb" />
<arg value="." />
</exec>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
更新:
關於Github的討論。
考慮使用Apache CXF Utils作為替代方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.