我有一个xsd文件,当使用jaxb-2 maven插件编译时,它会生成java源代码。我的xsd的标题是:
<schema targetNamespace="example.company.com"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:prefix="example.company.com">每当我试图获得用于使用以下代码进行封送/解封的JAXBContext时:
JAXBContext jc = JAXBContext.newInstance("com.company.example", com.company.example.ObjectFactory.class.getClassLoader());我的控制台中有数百条错误消息,如下所示:
没有为XmlSchema找到com.company.example注释
在所有这些错误消息之后,封送处理工作。不过,我想消除这些错误。
jaxb2 maven插件在我的pom中定义如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<dependencies>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>net.sourceforge.ccxjc</groupId>
<artifactId>cc-xjc-plugin</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>-enableIntrospection -verbose</arguments>
<schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<packageName>com.company.example</packageName>
<verbose>true</verbose>
<failOnNoSchemas>true</failOnNoSchemas>
<clearOutputDir>false</clearOutputDir>
<arguments>-copy-constructor</arguments>
<extension>true</extension>
</configuration>
</plugin>发布于 2014-08-26 17:30:32
看起来好像没有编译XML生成的包info.java(包含@XmlSchema注释)文件以及其他模型文件。
更新
我正在运行OSGi并使用Java
您应该确保在清单中导入javax.xml.bind包。它们可能是ClassLoader环境中的javax类的问题。
发布于 2014-08-26 15:15:01
您没有将包映射到名称空间"http://www.w3.org/2001/XMLSchema“。要做到这一点,请将标题设置为:
<schema
xmlns=...
xmlns:po=....
targetNamespace="http://www.w3.org/2001/XMLSchema"
>另外,将此注释添加到类中:
@javax.xml.bind.annotation.XmlSchema (namespace = "http://www.w3.org/2001/XMLSchema")有关XmlSchema的更多信息,请参见以下文档:http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlSchema.html
https://stackoverflow.com/questions/25508845
复制相似问题