Reputation: 780
I have an xsd file that, when compiled using the jaxb-2 maven plugin, generates java source. The header for my xsd is:
<schema targetNamespace="example.company.com"
elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:prefix="example.company.com">
Whenever I attempt to get the JAXBContext for use in marshaling/unmarshaling using this code:
JAXBContext jc = JAXBContext.newInstance("com.company.example", com.company.example.ObjectFactory.class.getClassLoader());
I get hundreds of error messages in my console that look like this:
No XmlSchema annotation found for com.company.example
After all of those error messages, the marshaling works. I would like to get rid of the errors though.
The jaxb2 maven plugin is defined in my pom like so:
<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>
Upvotes: 1
Views: 1534
Reputation: 149017
It looks as though the package-info.java (that contains the @XmlSchema
annotation) file that was generated along with the other model files from the XML Schema is not being compiled.
I am running OSGi and using Java SE
You should make sure you import the javax.xml.bind
package in your manifest. Their can be ClassLoader
issues with javax
classes in OSGi environments.
Upvotes: 1
Reputation: 994
You didn't map your package to the namespace "http://www.w3.org/2001/XMLSchema". To do this, make your header like this:
<schema
xmlns=...
xmlns:po=....
targetNamespace="http://www.w3.org/2001/XMLSchema"
>
Also, add this annotation to your class:
@javax.xml.bind.annotation.XmlSchema (namespace = "http://www.w3.org/2001/XMLSchema")
For more information about XmlSchema, see these docs: http://docs.oracle.com/javase/7/docs/api/javax/xml/bind/annotation/XmlSchema.html
Upvotes: 0