XSD和WSDL在不同的目录中 [英] XSD and WSDL in different directories
问题描述
在我的工作中,使用jaxws-maven-plugin进行代码生成. 我有两个项目是"common"和"client".结构大致如下:
At my work used jaxws-maven-plugin for code generation. I have two projects are "common" and'' client ". Structure roughly as follows:
app/
common/
resource/
some.xsd
client/
resource/
some.wsdl
如何使用项目"common"中的xsd从项目"client"中的wsdl生成类?
How can I generate classes from wsdl in the project "client", using the xsd from the project "common"?
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>
推荐答案
首先,您应该遵循Maven约定,将src/main/resources/
目录用于资源.
First of all you should stick to the maven conventions, use src/main/resources/
directories for resources.
之后,您可以使用 maven-dependency-plugin:unpack-dependencies
解压缩common
jar文件以访问some.xsd
:
After doing that then you can use the maven-dependency-plugin:unpack-dependencies
to unpack the common
jar file to access the 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
已绑定到generate-sources
阶段,因此在jaxws-maven-plugin
之前添加maven-dependency-plugin
到同一阶段,可以确保在应用wsimport
目标之前将所有内容解压.
The jaxws-maven-plugin
is bound to the generate-sources
phase so adding the maven-dependency-plugin
before the jaxws-maven-plugin
and to the same phase makes sure that it unpacks everything before applying the wsimport
goal.
确保<bindingDirectory/>
和<wsdlDirectory/>
正确.
如果另一个项目中有*.xsd
文件,这就是应该怎么做. 从不访问具有相对路径的其他项目.每个项目都只能使用依赖机制来访问其他资源.
This is how you should do it if you have the *.xsd
files in another project. Never access other projects with relative paths. Each project should only access other resources using the dependency mechanism.
这篇关于XSD和WSDL在不同的目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!