Distributing XSD Files to Multiple Maven Artifacts

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

Maven Artifact A is one of many web services that defines an XSD scheme with request and response definitions. (Src / primary / resources / xsd)

Artifact A depends on Artifact B, which is a simple JAR project and contains many basic XSDs with low-level descriptions. (Src / primary / resources / xsd)

XIF in Artifact A uses type definitions (include) that are specified once in Artifact B.

If at all possible, I would really like to know how to include the xsd files that are in the bank, which is downloaded as a dependency on maven, and how to enable webservice xsd (and wsdl) in an IDE such as Netbeans and Eclipse.

If this approach seems exotic - are there better methods for clean design?

Update

First, here is a simple example of how I expect this circuit 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 solutions to such a problem, but I don't know how to implement them in my environment:

I know that in the Directory Registries built into the (netbeans7.1) IDE (for dev environmentemnt) and available as Maven plugins (for a production environment), this should be able to specify an alias in the location of the schema file. This alias should then be used as the location of the schema.

However, I do not know how to specify Catalog.xml, which accesses the schemas inside the JAR file. For me, this seems to be the same problem as specifying it directly in the layout of the circuit. There is also the overhead of maintaining a directory for each WAR project, which I would prefer not to take, if at all possible.

As for the Maven plugin, I haven't found anything yet.

Other sources implement their own directory recognizer in the context of jax-b, but I do not see a possible hook for implementing such a resolver in Java-WS yet and how it should work in combination with the maven plugin or IDE directory identifier mentioned above ...

+7
source share
1 answer

I think your question is reasonable. In the past, I often found that I have a Maven module that must perform special processing of files that can be found in dependent JARs.

What I did in the past is to make Artifact B dependent on Artifact A. Then, in pom.xml of Artifact A, I use the special Maven dependency plugin configuration 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> 

Now your XSD files of interest can be found in the destination Artifact A directory, and from there you can do whatever you want with them. You can include them as resources, link to them from other XSD files, embed them in your own JARs or whatever! As you can see from the configuration, you also do not need to put them in the target directory; you can put them directly in the /src/main/resources directory.

You can add this configuration to any Maven module that you want all modules to work the same. The best part about this approach is that it will also work with Eclipse through M2Eclipse.

+6
source

All Articles