Generate Java Classes from XSD with default package name and XSD namespace - jaxb

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.

Related

linux maven vs mac maven

we are working in a multi-module maven project in both Linux machine and Mac machine with the same pom.xml, and we run the below command in offline mode
mvn install antrun:run -o
The problem is maven downloads a different version of plugins for the same pom.xml file. The difference is listed here comparison of Mac and Linux machine plugin jars
We did not specify the version of plugins in pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>Testing</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<inherited>false</inherited>
<executions>
<execution>
<id>Test</id>
<phase>install</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>test.mac_linux</groupId>
<artifactId>Test</artifactId>
<version>1.0</version>
<file>${home_dir}/Downloads/jackson-databind-2.4.4.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<configuration>
<phase>install</phase>
<target>
<zip destfile="${home_dir}/linux_mac_testing_maven/Testing_mac.zip">
<fileset dir="${home_dir}/.m2/repository/" includes="**/*" />
</zip>
</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources-WEB_INF</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${home_dir}/linux_mac_testing_maven/Resources/</outputDirectory>
<resources>
<resource>
<directory>${home_dir}/CustomReport_files/</directory>
<includes>
<include>**.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
does anybody know why maven differs its characteristics when subjected to a different operating system?
You mention in https://jira.apache.org/jira/projects/MNG/issues/MNG-6470 you are using different versions of Maven (3.5 on Mac and 3.3.9 on Linux). Please update both to latest (3.5.4) and then compare results.

Maven equivalent of eclipse "clean project"

I have a multi-level maven project, which includes a major module which references all the other (also maven) projects:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.evercompliant</groupId>
<artifactId>PipelineMultiModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Pipeline Multi Module</name>
<description>Maven multi module project</description>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../AggregationHandler</module>
<module>../CrawlerUtils</module>
<module>../CrawlManager</module>
<module>../CrawlerDevLibrary</module>
<module>../DigestManager</module>
<module>../GCrawler/GoogleCrawler</module>
<module>../UrlService</module>
<module>../WebPageCapture</module>
<module>../WhoisParser</module>
<module>../TextClassifier</module>
<module>../scanpipelineservice</module>
</modules>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
In order to do a full build on windows, I need to execute maven clean and maven install from eclipse.
For some reason, if I don't execute eclipse's "Clean all Projects" between mvn clean and mvn install, the artifact doesn't include the binaries of my project.
For example, the jar created for the AggregationHandler project, will include all of its dependencies (CrawlerUtils, for example), but not the code of AggregationHandler itself.
As I said, it could be fixed by executing "Clean all projects".
Here's the pom.xml file of the AggregationHandler project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>AggregationHandler</artifactId>
<name>Aggregation Handler</name>
<dependencies>
<dependency>
<groupId>com.evercompliant</groupId>
<artifactId>CrawlerUtils</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.evercompliant.aggregationhandler.service.DoAction</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>com.evercompliant.aggregationhandler.service.DoAction</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<parent>
<groupId>com.evercompliant</groupId>
<artifactId>PipelineMultiModule</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../PipelineMultiModule</relativePath>
</parent>
Problem is, I now need to build this project on a linux environment, without eclipse. Is there any change that I can do to the pom.xml file(s) in order to fix this problem?

How to disable hostname verification or allow all certificates when using maven-jaxb2-plugin?

Currently, I'm using the maven-jaxb2-plugin to generate Java artefacts while consuming a soap web services via SSL. I configured my pom.xml per the answer here. But the certificate I used didn't contain any DNS/IP subjects of server. Then there will be some javax ssl exceptions for no alternative name for IP address if my wsdl url is like 'https://XXX.XXX.XXX.XXX:9443/services/testWS?wsdl' in pom.xml. Is there any way to configure jaxb to disable the hostname verification? Thanks.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>javax.net.ssl.keyStore</name>
<value>${basedir}/src/test/key.jks</value>
</property>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>changeit</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>testproxy.wsdl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>my.wsdl.testproxy</generatePackage>
<schemas>
<schema>
<url>http://XXX.XXX.XXX.XXX:9443/services/testWS?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I generally don't recommend builds which depend on online resources of any kind. Consider making a local copy of the WSDL you want to compile and use a catalog file to rewrite the URI of the online resource to a local resource.
Disclaimer: I'm the author of the maven-jaxb2-plugin.

m2e fails to execute wro4j plugin

I would like to use wro4j maven plugin in a project. I works using mvn command line, but not in Eclipse/m2e.
I tried both lifecycle-mapping customization, and wroj4j-m2e integration plugin.
Here is the error with lifecycle-mapping customization :
Execution default of goal ro.isdc.wro4j:wro4j-maven-plugin:1.6.0:run failed: Plugin ro.isdc.wro4j:wro4j-maven-plugin:1.6.0 or one of its dependencies could not be resolved: Failed to collect dependencies for ro.isdc.wro4j:wro4j-maven-plugin:jar:1.6.0 () (ro.isdc.wro4j:wro4j-maven-plugin:1.6.0:run:default:process-resources)
The log of m2eclipse (in .plugins\org.eclipse.m2e.logback.configuration) is empty about this error, even with debug output selected in Eclipse maven preferences.
m2e version : 1.2.0.20120903-1050
eclipse version : Juno Service Release 1
Here is the pom.xml (extract)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<wro4j.version>1.6.0</wro4j.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<configuration>
<destinationFolder>${project.build.directory}/</destinationFolder>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<wroFile>${basedir}/src/main/config/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/config/wro.properties</extraConfigFile>
<targetGroups>gss</targetGroups>
<cssDestinationFolder>${project.build.directory}/${project.build.finalName}/styles/</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/${project.build.finalName}/scripts/</jsDestinationFolder>
<contextFolder>${basedir}/src/main/</contextFolder>
<ignoreMissingResources>false</ignoreMissingResources>
<wroFile>${basedir}/src/main/config/wro.xml</wroFile>
</configuration>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- configure #!# m2eclipse -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<versionRange>[1.0,]</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

JAXB fails to generate Java classes for XBRL

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?

Resources