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?
Related
I have 2 sets of XSDs, One for Inbound operations and other for outbound operations. Both XSD sets have similar namespace but since are from different sources need to be maintained seperately in the same codeset. Each XSD set has deeply nested classes and generates roughly 650 classes.
I am using a Maven JAXB plugin to generate Java classes.
If I specify an <outputDirectory>, the file generation fails because of namespace collision between Outbound and Inbound operation. If I specify <packageName>, all classes are generated in the same package which results in namespace collision within Inbound operations.
Is there a way in which Maven will follow the package name provided by XSD namespace and prefix the package name with 'inbound' or 'outbound' to seperate the resulting package names. For e.g the packages create by XSD is
com.example.operation
com.example.operation.v1
Can it be modified to
inbound.com.example.operation
inbound.com.example.operation.v1
My Maven pom.xml file
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<groupId>com.example</groupId>
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-integration-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sample-integration-model</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>xjc-outbound</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<laxSchemaValidation>true</laxSchemaValidation>
<outputDirectory>target/jaxb2/outbound</outputDirectory>
<sources>
<source>src/main/xsd/OutboundXsd/RequestMessagesDictionary</source>
<source>src/main/xsd/OutboundXsd/ResponseMessagesDictionary</source>
</sources>
</configuration>
</execution>
<execution>
<id>xjc-inbound</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<laxSchemaValidation>true</laxSchemaValidation>
<outputDirectory>target/jaxb2/inbound</outputDirectory>
<sources>
<source>src/main/xsd/InboundXsd/RequestMessagesDictionary</source>
<source>src/main/xsd/InboundXsd/ResponseMessagesDictionary</source>
</sources>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can tell Maven to set the generated classes in a given package.
Use <generatePackage>desired.package</generatePackage> inside the execution tag.
It is well documented here.
I use maven-jaxb2-plugin. It generate my classes in the correct directory, but on Eclipse Neon.2 Release (4.6.2), the folder is not automaticaly added to the classpath.
Here is my plugin config :
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<addCompileSourceRoot>true</addCompileSourceRoot>
<generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<generatePackage>foo.bar.pojo</generatePackage>
</configuration>
</plugin>
</plugins>
</build>
Is it possible with maven-jaxb2-plugin to define the genearted directory as source folder ? If yes, how ?
Eclipse shows me an error in the pom.xml on <execution> :
Execution default of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: A required class was missing while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate: com/sun/xml/bind/api/ErrorListener
To fix my problem, I had to change the version of the plugin.
From :
<version>0.13.1</version>
To :
<version>0.12.1</version>
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'm on my first Java-Spring project. I need to communicate with a couple of webservices. I have some WSDL's provided, so i'm using Jax2B to autogenerate classes.
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<url>http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
My project is a web project. The problem here is, my classes are generated in the targets folder, and not in my project. Does somebody have ideas how to fix this? Classes are generated properly, but not at the proper directory. As you can see, i'm using a test wsdl and mockup names at the moment. I followed this tutorial: http://spring.io/guides/gs/consuming-web-service/
Many thanks in advance
Author of the maven-jaxb2-pugin here.
target/generated-sources/xjc IS the proper directory. This is how generated code is handled in Maven builds, you never generate anything into src/main/java.
The maven-jaxb2-plugin also adds this directory to the Maven's sources directories. You just have to make sure that this directory is considered a source directory by your IDE. In Eclipse, m2eclipse plugin does this automatically when you do "Update project".
See this part of the docs.
I use this plugin to add the classes generated to source....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/xjc</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I had prepared some xsd under src\main\resources folder structure and created a.jar file now I want to generate the scheam objects for xsd in a.jar in another application like generateSource application can anybody help me in writing the maven plugin in pom.xml file
like what all dependencies and plugins required.
1st you need to extract the jar which contains XSD using maven-dependency-plugin like this.
<plugin>
<!-- Unpack the jar into target directory -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>unpack</id>
<phase>validate</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${unpack.directory}</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<includeGroupIds>com.companyname</includeGroupIds>
<includeArtifactIds>jarname</includeArtifactIds>
<excludes>**/*.html,samples/**</excludes>
</configuration>
</execution>
</executions>
Later you need to use maven-jaxb2-plugin to convert extracted xsds to java classes as mentioned below.
<plugin>
<!-- Convert XSD to java classes using jaxb plugin -->
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<extension>true</extension>
<generateDirectory>${generated.source.directory}</generateDirectory>
</configuration>
<executions>
<execution>
<id>Generate java-from-schema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>${unpack.directory}/XXX</schemaDirectory>
<catalog>${unpack.directory}/catalog</catalog>
<schemaIncludes>
<schemaInclude>aaa/*.xsd</schemaInclude>
<schemaInclude>bbb/*.xsd</schemaInclude>
<schemaInclude>ccc/*.xsd</schemaInclude>
</schemaIncludes>
</configuration>
</execution>
</executions>
Please see the separate schema compilation documentation.