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.
Related
I have unit tests written in junit & integration tests in cucumber. I am trying to separate unit test & integration test execution. i know this question already exists. I tried a lot of writings on the internet but did not help. Atm I can execute cucumber test only from IDE and not through CLI. "mvn test" command executes only unit tests and not integration test. Please help.
mvn test -Dtest=RunCucumberIntegrationTest -Dcucumber.options="-tags #integration"
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${failsafe-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<excludes>
<exclude>**/RunCucumberIntegrationTest.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/RunCucumberIntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
Here is the sample pom.xml file. I can execute any profile based on my requirement.
<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.gtihub.frostyaxe</groupId>
<artifactId>StackOverflow-61781205</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>junit</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<dependencies>
<!-- Force using the latest JUnit 47 provider -->
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M4</version>
</dependency>
</dependencies>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<configuration>
<includes>
<include>${project.basedir}/src/test/java/unit/testclasses/*.java</include>
<exclude>${project.basedir}/src/test/java/integration/testclasses/*.java</exclude>
</includes>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>testng</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
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 using spock framework and groovy for my tests. Also I'm using allure-spock-1.0-adaptor for generating Allure reports. Reports looks fine, but not showing steps in results. All groovy methods are annotated with #Step but still not logged in report.
How to fix that?
Check FAQ. I suppose you need to add javaagent. AspectJ is used to process steps, attachments and parameters.
Solved by adding AspectJ and allure-junit-adaptor into pom.xml. Now #Step is handled correctly with spock tests.
See example of pom.xml :
<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>allure.spock.demo</groupId>
<artifactId>allure-spock</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<allure.version>1.4.23.HOTFIX1</allure.version>
<aspectj.version>1.8.9</aspectj.version>
<compiler.version>1.7</compiler.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
<includes>
<include>**/*Spec.*</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.1-groovy-2.4-rc-3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-junit-adaptor</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-spock-1.0-adaptor</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
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?
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.