XSD and WSDL in different directories

In my work, I used jaxws-maven-plugin to generate code. I have two projects: "general" and "client". The structure is approximately as follows:

app/  common/   resource/    some.xsd  client/   resource/    some.wsdl 

How can I generate classes from wsdl in the project β€œclient” using xsd from the β€œcommon” project?

pom.xml:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <executions> <execution> <goals> <goal>wsimport</goal> </goals> <configuration> <verbose>true</verbose> <bindingFiles> <bindingFile>${project.parent.basedir}/common/resource/some.xsd</bindingFile> </bindingFiles> <wsdlFiles> <wsdlFile>/resource/some.wsdl</wsdlFile> </wsdlFiles> </configuration> </execution> </executions> </plugin> 
+6
source share
1 answer

First of all, you must adhere to the maven rules, use src/main/resources/ directories for resources.

After that, you can use maven-dependency-plugin:unpack-dependencies to unzip the common jar file to access some.xsd :

 <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> <parent> <groupId>com.stackoverflow.Q13155047</groupId> <artifactId>app</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>client</artifactId> <name>${project.artifactId}-${project.version}</name> <properties> <schema.location>${project.build.directory}/schemas</schema.location> </properties> <dependencies> <dependency> <groupId>com.stackoverflow.Q13155047</groupId> <artifactId>common</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5.1</version> <executions> <execution> <id>unpack-dependencies</id> <phase>generate-sources</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <includes>**/*.xsd</includes> <outputDirectory>${schema.location}</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxws-maven-plugin</artifactId> <executions> <execution> <goals> <goal>wsimport</goal> </goals> <configuration> <verbose>true</verbose> <bindingDirectory>${schema.location}</bindingDirectory> <bindingFiles> <bindingFile>some.xsd</bindingFile> </bindingFiles> <wsdlDirectory>src/main/resources</wsdlDirectory> <wsdlFiles> <wsdlFile>some.wsdl</wsdlFile> </wsdlFiles> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> 

jaxws-maven-plugin tied to the generate-sources phase, so add maven-dependency-plugin to jaxws-maven-plugin and make sure that it unpacks everything before applying the wsimport target.

Make sure that <bindingDirectory/> and <wsdlDirectory/> are correct.


So you should do this if you have *.xsd files in another project. Never access to other projects with relative paths. Each project should have access only to other resources using the dependency mechanism.

+6
source

All Articles