Here is a small Example of what I would like to achieve:
Maven Artifact A is one of many Webservices and defines a XSD Schema with definitions for Requests and Responses. (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)
The XSDs in Artifact A use the type definitions (include) that are specified once in Artifact B.
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?
update
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:
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.
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.
Concerning the Maven plugin I haven't found out anything conclusive yet.
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...
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.
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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With