I'm trying to add an interface using the jaxb2-basics artifact from the jaxb2_commons maven group.
My pom.xml contains the following dependencies
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.7</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.6.4</version>
</dependency>
and the plugin configuration looks like
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb22-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>jaxb-generate-messages-in</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
<schemaLanguage>XMLSCHEMA</schemaLanguage>
<schemaDirectory>src/main/schema</schemaDirectory>
<schemaIncludes>
<include>MESSAGES-IN.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/binding</bindingDirectory>
<bindingIncludes>
<include>messages-in-binding.xjb</include>
</bindingIncludes>
<episodeFile>${project.build.directory}/generated-sources/messages-in/META-INF/jaxb-messages-in.episode</episodeFile>
<generateDirectory>${project.build.directory}/generated-sources/messages-in</generateDirectory>
<extension>true</extension>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
</configuration>
</execution>
<execution>
<id>jaxb-generate-messages-out</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<specVersion>2.2</specVersion>
<schemaLanguage>XMLSCHEMA</schemaLanguage>
<schemaDirectory>src/main/schema</schemaDirectory>
<schemaIncludes>
<include>MESSAGES-OUT.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/binding</bindingDirectory>
<bindingIncludes>
<include>messages-out-binding.xjb</include>
</bindingIncludes>
<episodeFile>${project.build.directory}/generated-sources/messages-out/META-INF/jaxb-messages-out.episode</episodeFile>
<generateDirectory>${project.build.directory}/generated-sources/messages-out</generateDirectory>
</configuration>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
</configuration>
</plugin>
As you can see from the above, there are two invocations of xjc, which both work. Focusing on the first one, my bindings file
<jaxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="xjc"
version="1.0">
<jaxb:bindings schemaLocation="../schema/MESSAGES-IN.xsd" node="/xs:schema">
<jaxb:globalBindings typesafeEnumMaxMembers="3000">
<jaxb:serializable uid="1"/>
</jaxb:globalBindings>
<jaxb:schemaBindings>
<jaxb:package name="com.whatever.messages.request"/>
</jaxb:schemaBindings>
<jaxb:bindings node="//xs:simpleType[#name='YesOrNo']">
<jaxb:class ref="com.whatever.messages.YesOrNo"/>
</jaxb:bindings>
<jaxb:bindings noade="//xs:complexType[#name='someLogin']">
<jaxb:class name="LoginRequest">
<jaxb:javadoc><![CDATA[A Login request message.]]>
</jaxb:javadoc>
</jaxb:class>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
works like a charm; but, when I attempt to add an interface to 'LoginRequest'...
<jaxb:bindings node="//xs:complexType[#name='someLogin']">
<jaxb:class name="LoginRequest">
<jaxb:javadoc><![CDATA[A Login request message.]]>
</jaxb:javadoc>
</jaxb:class>
<inheritance:implements>com.whatever.messages.Request</inheritance:implements>
</jaxb:bindings>
I receive the error message
Error while parsing schema(s).Location [ file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/binding/messages-in-binding.xjb{19,42}].
com.sun.istack.SAXParseException2; systemId: file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/binding/messsages-in-binding.xjb; lineNumber: 19; columnNumber: 42; compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings.
which reports that the location was
Error while generating code.Location [ file:/C:/Users/justme/Documents/NetBeansProjects/someproject/src/main/schema/MESSAGES-IN.xsd{106693,54}].
which happens to correspond to
<xs:complexType name="someLogin" mixed="true">
...
</xs:complexType>
Now, I've tried a second directive to bind the interface to the XSD element
<xs:element name="someLogin" type="someLogin" substitutionGroup="externalMethod"/>
But I just get the same error message with the element's line number as the location.
Obviously one wants to attach an interface to a class, and all of the examples look pretty close to my bindings file, but something must be wrong.
My environment is
Apache Maven 3.0.4 (r1232337; 2012-01-17 02:44:56-0600)
Maven home: C:\Program Files\NetBeans 7.2.1\java\maven
Java version: 1.7.0_07, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jdk1.7.0_07\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Can someone explain why xjc believes the extension is operating on the wrong XSD type?
In the construction
<jaxb:bindings
node="//Xs:complexType[#name='someLogin">
...
</jaxb:bindings>
the node attribute is expected to be an XPath expression. (Or so it says at Oracle). Try adding the closing square bracket to make it one, and see if that helps.
Related
I have a Vendor.xsd, where the namespace definition is referencing a vendor specific namespace http://vendor.com/xjc-plugins. A snippet is given below:
...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:common="http://annox.dev.java.net"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:vendor="http://vendor.com/xjc-plugins"
elementFormDefault="qualified"
jaxb:extensionBindingPrefixes="vendor common"
jaxb:version="2.0">
...
xs:complexType name="VendorType">
<xs:annotation>
<xs:appinfo>
<vendor:package>vendor.package</vendor:package>
</xs:appinfo>
</xs:annotation>
...
When I try to generate jaxbs by using either xjc from command line or maven-jaxb22-plugin the following exception occurs:
Unsupported binding namespace "http://vendor.com/xjc-plugins". Perhaps you meant "http://annox.dev.java.net"?
The maven plugin I am using is given here:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb22-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>Vendor.xsd</include>
</schemaIncludes>
<generatePackage>com.vendor.model</generatePackage>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>1.0.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>1.11.1</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-tools</artifactId>
<version>1.11.1</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
Any ideas welcome ?
You do not seem to include your XJC plugin in plugins section of the maven-jaxb2-plugin configuration. Binding namespace must be acknowledged by some plugin. You only include jaxb2-basics but not the plugin which would acknowledge http://vendor.com/xjc-plugins.
I tried to use JAXB2 simplify plugin using the XJC 2.2.4.
D:\>xjc -d . -extension -p org.my.space sample.xsd parsing a schema... [ERROR] Unsupported binding namespace
"http://jaxb2-commons.dev.java.net/basic/simplify". Perhaps you meant
"http://jaxb.dev.java.net/plugin/code-injector"? line 7 of file:/D:/sample.xsd
Failed to parse a schema.
sample.xsd has the declared simplify
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
jaxb:extensionBindingPrefixes="simplify"
xmlns="http://www.example.org/sampleXML" targetNamespace="http://www.example.org/sampleXML"
elementFormDefault="qualified">
any thoughts?
EDIT:
I tried other way around with bindings file xjb and still the same error. Does it mean my XJC version(2.2) does not support JAXB2 simplify ?
xjc -d . -extension -b bindings.xjb sample.xsd
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
extensionBindingPrefixes="simplify">
<bindings schemaLocation="sample.xsd" node="/xs:schema">
<bindings
node="/xs:schema/xs:complexType[#name='dlist']/xs:choice/xs:element[1]">
<simplify:as-element-property />
</bindings>
</bindings>
</bindings>
I switched to maven jaxb2 plugin and with some more efforts it worked fine. For people who have trouble in future. This setup works just fine in JDK 1.6 (for those still cant migrate).
pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- plugin to compile schemas to JAXB classes -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb21-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>generate-JAXB</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>sample.xsd</include>
</schemaIncludes>
<cleanPackageDirectories>true</cleanPackageDirectories>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
I did not use binding.xjb as I have included the simplify directly in the schema (as i have access).
sample.xsd
<xs:complexType name="doclist">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property />
</xs:appinfo>
</xs:annotation>
<xs:element name="document1" type="type1" />
<xs:element name="document2" type="type2" />
</xs:choice>
</xs:sequence>
<xs:attribute name="heading" type="xs:string" />
</xs:complexType>
I want to have a project A with some common used XML schema files and some java classes dependent on the generated classes (generated from jaxb), using namespace a and package a, and I want to have a project B dependent on project A.
in project B i want to have a XML schema file using some XML types from project A, project b has namespace b, then JAXB needs to generate java classes from schema b into the package b.
I know that episodes and catalogs might help, but i can not prevent jaxb to create the java classes comming from schema a twice in project b.
here is my maven configuration:
project A:
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<schemaIncludes>
<include>wsdl/WebServiceBaseRequestResponse.xsd</include>
</schemaIncludes>
<generatePackage>a</generatePackage>
<episode>true</episode>
</configuration>
</plugin>
</plugins>
</build>
Project B :
<!-- Used to pull XSD files from the JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-xsd-files</id>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>a</groupId>
<artifactId>a-xsd</artifactId>
<version>${project.version}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<includes>wsdl/*.xsd</includes>
<outputDirectory>${project.basedir}/target/xsd-includes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<episodes>
<episode>
<groupId>a</groupId>
<artifactId>sca-xsd</artifactId>
<version>${project.version}</version>
</episode>
</episodes>
<episode>false</episode>
<schemaIncludes>
<include>wsdl/b.xsd</include>
</schemaIncludes>
<generatePackage>b</generatePackage>
</configuration>
</plugin>
b.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema version="1" targetNamespace="a"
xmlns:tns="a" xmlns:com="b"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="a" schemaLocation="..relPathTo/target/xsd-includes/a.xsd>
<xs:element name="addShipmentOrderResult">
<xs:annotation>
<xs:documentation>
Result object for addShipmentOrder.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="com:baseResult">
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
In this way you're not using the episodes, because you unpack the xsd within B project, so regenerates the classes from A project.
You should using the following configuration
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-Xannotate</arg>
<arg>-Xnamespace-prefix</arg>
<arg>-nv</arg>
</args>
<extension>true</extension>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<fileset>
<directory>${basedir}/src/main/resources/schema/project/b</directory>
<includes>
<include>*.xsd</include>
</includes>
</fileset>
</schema>
<schema>
<dependencyResource>
<groupId>com.project.a</groupId>
<artifactId>artifact.a</artifactId>
<resource>schema/a.xsd</resource>
</dependencyResource>
</schema>
</schemas>
<episodes>
<episode>
<groupId>com.project.a</groupId>
<artifactId>artifact.a</artifactId>
</episode>
</episodes>
<debug>true</debug>
<verbose>true</verbose>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-namespace-prefix</artifactId>
<version>1.1</version>
</plugin>
</plugins>
</configuration>
</plugin>
Remember to add as dependency the project A.
I am trying to add javax.persistence.Id as an annotation to a filed and generate as Java objects through Maven JAXB plugin. However I run into class not found exception for javax.persistence.id I did make sure that the javax.persistence is included in the maven dependency and I see maven pulling it as dependency but when I run through jaxb plugin it won't work.
Here is my XML <xsd:complexType name="MyTable">
<xsd:sequence>
<xsd:element name="id" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
Here is my binding.xjb file
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox">
<jaxb:bindings schemaLocation="mytable.xsd">
<jaxb:bindings node="xs:complexType[#name='MyTable']/xs:sequence/xs:element[#name='id']">
<annox:annotate target="field">
<annox:annotate annox:class="javax.persistence.Id"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
Here is my relevant Pom.xml
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>myschema</schemaDirectory>
<bindingIncludes>
<include>binding.xjb</include>
</bindingIncludes>
<extension>true</extension>
<args>
<arg>-Xvalue-constructor</arg>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin> <groupId>org.jvnet.jaxb2_commons</groupId>
jaxb2-basics 0.6.4
org.jvnet.jaxb2_commons
jaxb2-basics-annotate 0.6.4
org.jvnet.jaxb2_commons
jaxb2-value-constructor
3.0
</plugins>
</configuration>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<versionRange>[0.7.4,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
However when I run Maven-->Generate-Sources I get this error
Caused by: org.jvnet.annox.parser.AnnotationElementParseException: Could not parse the annotation element.
at org.jvnet.annox.parser.XAnnotationParser.parse(XAnnotationParser.java:90)
at org.jvnet.jaxb2_commons.plugin.annotate.AnnotatePlugin.annotate(AnnotatePlugin.java:387)
... 31 more
Caused by: org.jvnet.annox.annotation.AnnotationClassNotFoundException: Annotation class [javax.persistence.Id] could not be found.
... 33 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.Id
If I simply add #Id annotation to any java class in the project then I can add and I see javax.persistence.Id getting imported with no problem. What is going wrong when I use maven & binding.xjb? Am I not defining the annotation properly? Many thanks!
I guess it's also the same problem that I had: you added javax.persistence as a Maven dependency, but not as a dependency to your JAXB plugin:
Add something like this (if you're using Hibernate):
</project>
...
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven-jaxb2-plugin.version}</version>
<executions>
...
</executions>
<configuration>
...
</configuration>
<dependencies>
<!-- Hibernate Persistence Annotations -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>${hibernate-jpa-2.0-api.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
</project>
I had a similar issue and was able to solve it with that. In the following example please note that I'm putting the annotations into the XSD and not into the XJB file but the Maven configuration should be similar.
Here's my XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
elementFormDefault="qualified" targetNamespace="http://www.gl-group.com/ewelding/schemas"
xmlns:ew="http://www.companyname.com/project/schemas"
xmlns:xmime="http://www.w3.org/2005/05/xmlmime" jaxb:extensionBindingPrefixes="annox"
xmlns:annox="http://annox.dev.java.net"
xmlns:ja="http://annox.dev.java.net/javax.xml.bind.annotation"
xmlns:jpa="http://annox.dev.java.net/javax.persistence"
xmlns:solrj="http://annox.dev.java.net/org.apache.solr.client.solrj.beans"
xmlns:jackson="http://annox.dev.java.net/com.fasterxml.jackson.annotation">
...
<xs:element name="Certificate">
<xs:annotation>
<xs:appinfo>
<annox:annotate>
<ja:XmlAccessorType value="NONE"/>
<jpa:Entity name="Certificate"/>
<solrj:Field value="testByOrderOf"/>
<jackson:JsonFormat shape="STRING" pattern="yyyy-MM-dd'T'HH:mm:ss'Z'" timezone="GMT"/>
</annox:annotate>
</xs:appinfo>
</xs:annotation>
...
<xs:element ref="ew:dateOfBirth">
<xs:annotation>
<xs:appinfo>
<annox:annotate target="field">
<solrj:Field value="dateOfBirth"/>
<jackson:JsonFormat shape="STRING" pattern="yyyy-MM-dd'T'HH:mm:ss'Z'" timezone="GMT"/>
</annox:annotate>
</xs:appinfo>
</xs:annotation>
</xs:element>
...
</xs:element>
And here are the relevant sections from my pom.xml:
...
<properties>
...
<maven-jaxb2-plugin.version>0.8.3</maven-jaxb2-plugin.version>
<jaxb2-basics.version>0.6.4</jaxb2-basics.version>
<jaxb2-value-constructor.version>3.0</jaxb2-value-constructor.version>
<solr-solrj.version>4.3.0</solr-solrj.version>
<jackson.version>2.2.2</jackson.version>
<hibernate-jpa-2.0-api.version>1.0.1.Final</hibernate-jpa-2.0-api.version>
...
</properties>
...
<build>
<plugins>
...
<!-- Generate Java sources from XSD schema files -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>${maven-jaxb2-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
<arg>-Xvalue-constructor</arg>
<arg>-Xinheritance</arg>
<arg>-enableIntrospection</arg>
</args>
<!-- Include our schema -->
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>certificate.xsd</include>
</schemaIncludes>
<bindingIncludes>
<bindings>certificate.xjb</bindings>
</bindingIncludes>
<generateDirectory>src/main/java</generateDirectory>
<generatePackage>com.company.project.generated</generatePackage>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>${jaxb2-basics.version}</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>${jaxb2-basics.version}</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-value-constructor</artifactId>
<version>${jaxb2-value-constructor.version}</version>
</plugin>
</plugins>
</configuration>
<dependencies>
<!-- SolrJ - only needed for the #Field annotation -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr-solrj.version}</version>
</dependency>
<!-- Jackson2 Annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Hibernate Persistence Annotations -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>${hibernate-jpa-2.0-api.version}</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
</build>
I had the same exception, this fixed it. Just be aware that my example puts everything into the XSD and not into the XJB... but the dependency-thing mentioned above should help you as well.
I'm trying to generate Java classes for types defined in XBRL.
My build process is based on Maven 2, and here are my trials. I only paste the build section, which relies on some properties:
package is the name of my target package
catalog is the path and file name of the catalog. because I have no internet connection, I have amny entries, but I think those are always necessary
-- TR9401 for XBRL resources --
SYSTEM http://www.xbrl.org/2003/XLink http/www.xbrl.org/2003/xl-2003-12-31.xsd
SYSTEM http://www.w3.org/1999/xlink http/www.xbrl.org/2003/xlink-2003-12-31.xsd
xsd.path is the directory where the XSD resides
xsd.file is the file name of the following minimalist XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.xbrl.org/2003/instance"
schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>
</xs:schema>
All plugins I have tried fail to import xl:nonEmptyURI.
But xl is mapped to http://www.xbrl.org/2003/XLink (which is in my catalog) which imports <import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink-2003-12-31.xsd"/> which defines nonEmptyURI
What's wrong? How can I fix it?
Apache CXF
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<xsdOptions>
<xsdOption>
<catalog>${catalog}</catalog>
<xsd>${xsd.path}/${xsd.file}</xsd>
<packagename>${package}</packagename>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
Fails with
parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'xl:nonEmptyURI' to a(n) 'type definition' component.
line 389 of cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd
jvnet maven-jaxb2-plugin
<plugin>
<!-- http://jaxb.java.net/ -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<catalog>${catalog}</catalog>
<schemaDirectory>${xsd.path}</schemaDirectory>
<generatePackage>${package}</generatePackage>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
</args>
</configuration>
</plugin>
The error is the same, a little more verbose
[INFO] Parsing input schema(s)...
[ERROR] Error while parsing schema(s).Location [ cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd{389,74}].
org.xml.sax.SAXParseException: undefined simple type 'xl:nonEmptyURI'
at com.sun.xml.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:180)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:175)
at com.sun.xml.xsom.impl.parser.DelayedRef.resolve(DelayedRef.java:110)
[...]
[ERROR] Error while parsing schema(s).Location [ cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd{412,77}].
org.xml.sax.SAXParseException: undefined simple type 'xl:nonEmptyURI'
at com.sun.xml.xsom.impl.parser.ParserContext$1.reportError(ParserContext.java:180)
at com.sun.xml.xsom.impl.parser.NGCCRuntimeEx.reportError(NGCCRuntimeEx.java:175)
at com.sun.xml.xsom.impl.parser.DelayedRef.resolve(DelayedRef.java:110)
[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.2:generate (generate) on project solvency2: Unable to parse input schema(s). Error messages should have been provided. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.2:generate (generate) on project solvency2: Unable to parse input schema(s). Error messages should have been provided.
Mojo jaxb2-maven-plugin
<plugin>
<!--http://mojo.codehaus.org/ -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${xsd.path}</schemaDirectory>
<packageName>${package}</packageName>
<catalog>${catalog}</catalog>
</configuration>
</plugin>
Same error, said differently by Xerces
[ERROR] file:[...]cache/http/www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd[472,74]
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'xl:nonEmptyURI' to a(n) 'simpleType definition' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
You definitely need all schemas to be downloaded and added to catalog in your case. I had a similar problem with generating Java classes, but I didn't use any catalogs at all just put all the schemas the XBRL uses into the same folder. The same way they're organized on XBRL site:
src\main\resources\xbrl\
xbrl-instance-2003-12-31.xsd
xbrl-linkbase-2003-12-31.xsd
xl-2003-12-31.xsd
xlink-2003-12-31.xsd
xbrl_bindings.xjb
Also I added a JAXB binding as you can see to resolve a conflict that raises during the source generation and put into the same folder.
xbrl_bindings.xjb:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
version="2.1">
<bindings schemaLocation="xl-2003-12-31.xsd" version="1.0">
<bindings node="//xs:schema//xs:element[#name='title']">
<property name="xlTitle"/>
</bindings>
</bindings>
Maven plugin configuration:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
<xsdOptions>
<xsdOption>
<bindingFile>${path.to.xsd}/xbrl_bindings.xjb</bindingFile>
<xsd>${path.to.xsd}/xbrl-instance-2003-12-31.xsd</xsd>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
Enjoy XBRL :)
In your catalog, you probably need to change SYSTEM with PUBLIC.
See also: this article
According to this article, PUBLIC is used for matching a namespace URI:
-- Match address.xsd by URL --
SYSTEM "http://www.example.com/address/address.xsd" "imports/address.xsd"
-- Match phone-number.xsd by namespace URI --
PUBLIC "http://www.example.com/phone-number" "imports/phone-number.xsd"
Did you download the XSD and put it in an imports folder?