在多个Maven工件上分发XSD文件 [英] Distribute XSD files over multiple Maven Artifacts

查看:104
本文介绍了在多个Maven工件上分发XSD文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要实现的目标的一个小例子:

Here is a small Example of what I would like to achieve:

Maven Artifact A是许多Web服务之一,并使用以下命令定义了XSD Schema: 请求和响应的定义. (src/main/resources/xsd)

Maven Artifact A is one of many Webservices and defines a XSD Schema with definitions for Requests and Responses. (src/main/resources/xsd)

工件A依赖工件B是一个简单的JAR项目,包含众多 低级类型描述的Master XSD的集合. (src/main/resources/xsd)

Artifact A depends on Artifact B wich is a simple JAR Project and contains a multitude of Master XSDs with low level Type descriptions. (src/main/resources/xsd)

工件A中的XSD使用指定的类型定义(包括) 一次在Artifact B中.

The XSDs in Artifact A use the type definitions (include) that are specified once in Artifact B.

如果可能的话,我真的很想知道如何包含位于jar中的xsd文件(作为maven依赖项加载)以及如何在诸如Netbeans和Eclipse的IDE中解析Webservice xsd(和wsdl).

If at all possible I would really like to know how to include xsd files that are located in a jar which is loaded as as a maven dependency and how to resolve the webservice xsd (and wsdl) in IDEs like Netbeans and Eclipse.

如果这种方法似乎很奇特-干净的设计是否有更好的做法?

If this approach seems to exotic - are there better practices for a clean design?

更新

首先,这是一个简单的示例,说明我希望架构包含的工作方式....

First here is a simple example of how I would expect the schema include to work....

Artifact A (WAR Module)
POM:
...
<artifactId>A</artifactId>
...
<dependency>
  <artifactId>B</artifactId>
  ...
</dependency>

Schema:
....
<xs:include schemaLocation="classpath://net/elfwyn/xsd/schema.xsd"/>
....

Artifact B (JAR Module)

Schema Location:
src/main/resources/net/elfwyn/xsd/schema.xsd

对于这样的问题,似乎有几种解决方法,但是我不知道如何在我的环境中实现它们:

There seem to be several sollutions for a problem like this, but I do not know how to implement them in my environment:

我知道(netbeans7.1)IDE中嵌入的目录解析器(对于开发环境),并且可以作为Maven插件(对于生产环境)使用,它们应该能够在架构文件的位置上指定别名.然后应将此别名用作架构位置.

I know of Catalog Resolvers embedded in the (netbeans7.1) IDE (for dev environemnt) and available as Maven Plugins (for productive environment), that should be able to specify an alias on the location of the schema file. This alias should then be used as the schema location.

但是,我不知道如何指定访问JAR文件中的架构的Catalog.xml. 对我来说,这似乎和直接在模式位置中指定它一样是一个问题. 此外,还有维护每个WAR目录的开销-如果可能的话,我不希望这样做.

However I do not know how to specify a Catalog.xml that accesses schemas inside a JAR File. To me it seems to be the same problem as specifying it in the schema location directly. Also there is the overhead of maintaining the catalog for each WAR - project wich I would rather not take if at all possible.

关于Maven插件,我还没有确定的结论.

Concerning the Maven plugin I haven't found out anything conclusive yet.

其他在jax-b的上下文中实现了自定义目录解析器, 但是我还看不到在Java-WS环境中实现这种解析器的可能钩子,以及它应如何与上述的maven-plugin或IDE Catalog解析器结合使用...

Other sources are implementing a custom catalog resolver in the context of jax-b, but I cannot yet see a possible hook for implementing such a resolver in a Java-WS environment, and how it should work in conjunction with the maven-plugin mentioned above or the IDE Catalog resolver...

推荐答案

我认为您的问题是合理的.过去,我经常发现我有一个Maven模块,该模块需要对可以在从属JAR中找到的文件进行特殊处理.

I think your question is reasonable. In the past I have often found that I have a Maven module that needs to do special processing on files that can be found in dependent JARs.

我过去所做的是使工件B成为工件A的依赖项.然后,在工件A的pom.xml中,我使用Maven依赖插件的特殊配置,如下所示:

What I have done in the past is to make Artifact B a dependency of Artifact A. Then in the pom.xml of Artifact A I use a special configuration of the Maven dependency plugin as follows:

<plugin>
    <!-- Used to pull XSD files from the JAR -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
          <execution>
              <id>unpack-xsd-files</id>
              <!-- Using the initialize phase because it is before the generate sources phase -->
              <phase>initialize</phase>
                   <goals>
                       <goal>unpack</goal>
                   </goals>
                   <configuration>
                        <artifactItems>
                            <artifactItem>
                                <!-- Artifact that Holds our custom templates -->
                                <groupId>com.mycorp</groupId>
                                <artifactId>artifact-b</artifactId>
                                <version>${artifact-b.version}</version>
                                <type>jar</type>
                            </artifactItem>
                         </artifactItems>
                         <includes>**/*.xsd</includes>
                         <outputDirectory>${project.basedir}/target/xsd-includes</outputDirectory>
                   </configuration>
            </execution>
    </executions>
</plugin>

现在,您可以在Artifact A的目标目录中找到您感兴趣的XSD文件,然后您就可以使用它们进行任何操作.您可以将它们包含为资源,可以从其他XSD文件中引用它们,也可以将它们嵌入自己的JAR或其他文件中!从配置中可以看到,您也不必将它们放在目标目录中.您可以将它们直接放入您的/src/main/resources目录.

Now your XSD files of interest can be found in the target directory of Artifact A and from there you can do anything you want with them. You can include them as resources, reference them from other XSD files, embed them in your own JARs or whatever! As you can see from the configuration, you also don't have to put them in your target directory; you could put them directly into your /src/main/resources directory.

您可以将此配置添加到所需的任何Maven模块中,以便多个模块都可以相同的方式工作.这种方法的好处是它也可以通过M2Eclipse与Eclipse一起使用.

You can add this configuration to any Maven module you want so that multiple modules can all work the same way. The nice thing about this approach is that it will also work from with Eclipse via M2Eclipse.

这篇关于在多个Maven工件上分发XSD文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆