Complicated Maven assembly - maven-2

I'm trying to write a maven assembly and I'm not sure how to continue. It's fairly complicated, so the examples I google don't really help. This is what I'm trying to do:
Create an installation file using launch4j. This part works, assuming the jar file is correctly assembled (hence the need for a maven assembly.)
The installation program contains some dependencies. These are assembled (currently) using the jar-with-dependencies descriptorRef. This works as well.
I need to include a war file (from another project) into the big jar. This is my confusion.
How do I create an assembly.xml that will do both the jar with dependencies (unpacking all of those jar files) and include a war file from another project (which is not unpacked).
Any help would be appreciated.

How do I create an assembly.xml that will do both the jar with dependencies (unpacking all of those jar files) and include a war file from another project (which is not unpacked).
Assuming you have a project structure similar to the one below (I'm assuming a simple structure since you didn't mention anything particular about it):
.
├── pom.xml
└── src
├── main
│   ├── assembly
│   │   └── uberjar.xml
│   └── java
│   └── com
│   └── stackoverflow
│   └── App.java
└── test
└── java
└── com
└── stackoverflow
└── AppTest.java
With the following pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q3762049</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- this is the war we want to include in the assembly -->
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
<!-- and below, the other dependencies -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/uberjar.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
As you can see,
We are not going to use the predefined jar-with-dependencies descriptor here, we are going to reuse it in our own custom assembly descriptor.
We have a dependency declared on the war with a runtime scope so that we'll be able to include it in the assembly.
And now, the custom uberjar.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<excludes>
<exclude>*:war</exclude>
</excludes>
</dependencySet>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>*:war</include>
</includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
This is a little variation of the jar-with-dependencies descriptor that will create a jar:
the dependencies except the war, unpacked
the war of the webapp, not unpacked
the classes from the project itself
As shown below:
$ mvn clean package
[INFO] Scanning for projects...
...
$ cd target; jar xvf Q3762049-1.0-SNAPSHOT-uberjar.jar
created: META-INF/
inflated: META-INF/MANIFEST.MF
created: org/
created: org/apache/
created: org/apache/commons/
created: org/apache/commons/lang/
created: org/apache/commons/lang/builder/
created: org/apache/commons/lang/enum/
created: org/apache/commons/lang/enums/
created: org/apache/commons/lang/exception/
created: org/apache/commons/lang/math/
created: org/apache/commons/lang/mutable/
created: org/apache/commons/lang/text/
created: org/apache/commons/lang/time/
inflated: META-INF/LICENSE.txt
inflated: META-INF/NOTICE.txt
inflated: org/apache/commons/lang/ArrayUtils.class
...
created: META-INF/maven/
created: META-INF/maven/commons-lang/
created: META-INF/maven/commons-lang/commons-lang/
inflated: META-INF/maven/commons-lang/commons-lang/pom.xml
inflated: META-INF/maven/commons-lang/commons-lang/pom.properties
inflated: my-webapp-1.0-SNAPSHOT.war
created: com/
created: com/stackoverflow/
inflated: com/stackoverflow/App.class

Related

Maven – Modules and moduleSet VS dependency and dependencySets

We have installation folder that we use with maven to pack a release up,
This Installation folder has some static files, and a pom.xml
The build goal is to copy the static files to the target installation folder and some zip artifacts from the repository – expand them and put them in the target folder under /unzipped.
installation folder:
/installation_folder
pom.xml
/some_files
/file1
/file2
Target folder should be like:
/target
/installation_files
/some_files
/file1
/file2
/unzipped
/prj1 - unzipped artifact prj1 from the repository
/prj2 - unzipped artifact prj2 from the repository
On this “installation pom” - I have a reference to assembly xml; I am able to copy the static files - and get artifacs from the repository,
The question is – to copy the zip from repository and expand them in the target/unzipped folder
should I use Modules and moduleSet or dependency and dependencySets?
Should the pom.xml + assembly.xml look like:
project.group
installation_project
pom
<modules>
<module>prj1</module>
<module>prj2</module>
</modules>
...
and assembly.xml:
<moduleSets>
<moduleSet>
<includes>
<include>*:*</include>
</includes>
<binaries>
<unpack>true</unpack>
</binaries>
</binaries>
</moduleSet>
Or should it look like this:
<project>
<groupId>project.group</groupId>
<artifactId>installation_project</artifactId>
<packaging>pom</packaging>
<dependencies>
<dependency>
<artifactId>prj1</artifactId>
<groupId>gruop_id</groupId>
<version>1.0-SNAPSHOT</version>
<type>zip</type>
</dependency>
<dependency>
<artifactId>prj2</artifactId>
<groupId>gruop_id</groupId>
<version>2.0</version>
<type>zip</type>
</dependency>
</dependencies>
...
and assembly.xml:
<dependencySets>
<dependencySet>
<outputDirectory>installation_files/unzipped/</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}</outputFileNameMapping>
<includes>
<include>*:*:zip</include>
</includes>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
Thank you!
Another way would be to just maven dependency plugin, with goal=unpack.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
<type></type>
<overWrite></overWrite>
<outputDirectory></outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
Another way is to use an assembly plugin but i find that quite cumbersome and is usually meant for more complex assembly creation than simple unzipping/zipping.

Maven WAR Overlays - including unpacked dependencies

I'm trying to set up a project using Maven and am a bit stuck with how to include some third party dependencies that need to be included unpacked in the resultant war file.
My project contains some custom ColdFusion code and includes Java dependencies, including ColdFusion packaged as a war file. I then am attempting to include some 3rd party ColdFusion code, which I've installed in my maven repository packaged as a jar, but I actually want to deploy it unpacked in the resultant war file. It's this unpacking of the 3rd party libraries that I'm stuck with. I'd really like this to be done BEFORE the war is build, so that I can use war:exploded during the development.
Currently my pom.xml looks something like this:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-webapp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- This is the war overlay -->
<dependency>
<groupId>com.adobe.coldfusion</groupId>
<artifactId>coldfusion</artifactId>
<version>9.0.1</version>
<type>war</type>
<scope>runtime</scope>
<optional>false</optional>
</dependency>
<!-- This is the 3rd party ColdFusion dependency -->
<dependency>
<groupId>org.corfield</groupId>
<artifactId>fw1</artifactId>
<version>1.2RC2A</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>my-webapp</finalName>
</build>
</project>
I've kind of got it doing what I want by modifying the build section as follows:
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.corfield</groupId>
<artifactId>fw1</artifactId>
<version>1.2RC2A</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/${project.artifactId}</outputDirectory>
<includes>**/*.cfc</includes>
</artifactItem>
</artifactItems>
<includes>**/*.cfc</includes>
<outputDirectory>${project.build.directory}/${project.artifactId}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The problem with this is that the package:unpack happens after the war is built, so the unpacked dependecies are not in the resulting war file.
I have also tried a few things with the assembly plugin and I came fairly close also by using something like this:
<assembly>
<id>${project.artifactId}</id>
<formats>
<format>war</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>org.corfield:fw1</include>
</includes>
<unpack>true</unpack>
<outputDirectory>/</outputDirectory>
</dependencySet>
<dependencySet>
<excludes>
<exclude>org.corfield:fw1</exclude>
</excludes>
<unpack>false</unpack>
<outputDirectory>/WEB-INF/lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/webapp</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
However that created a second war file named something like my-webapp-1.0-SNAPSHOT-my-webapp.war as well as the my-webapp-1.0-SNAPSHOT.war. The my-webapp-1.0-SNAPSHOT-my-webapp.war also included my-webapp-1.0-SNAPSHOT.war
At the end of the day I want my resultant war to look like:
org
|-- corfield
|-- framework.cfc
WEB-INF
|-- lib
|-- web.xml
index.cfm
(in reality there's a lot more to it than that, but that's enough to illustrate the point hopefully)
I think I'm pretty close but I'm just missing something I need. I'd be extremely grateful for any assistance.
For the maven-dependency-plugin approach, bind the unpack goal on the prepare-package phase (Maven 2.1+) instead of package.
References
Lifecycle Reference
Have you looked at the overlay option with maven-war-plugin? It esstentially allows you to unpack the ColdFusion war on top your site layout. I've done this with a combination of ColdFusion 9.x and Struts2. Doing a ColdFusion only overlay should make it real easy. You may want to create the ColdFusion war first. You can also then control the neo-*.xml files from your Maven project as well.

Custom maven assembly

I'm starting to work with Maven but am not yet successfully thinking in Maven's terms. I have a specific requirement and the docs aren't giving me enough clues, so I could use a bit of help:
I'd like to create an assembly that
builds a jar-with-dependencies like the "standard" target of this name, but excluding a couple of the resources. I want log4j.properties and a couple of other configuration files to not be in the jar.
builds a .ZIP file containing in its root directory the .jar from step 1 as well as the above mentioned config files.
I want to fire this assembly up from the command line (only), hence no need to tie to a phase (or goal? mojo?). Preferrably using either assembly:assembly or assembly:single.
Do I need a custom assembly descriptor for this?
And is it true I can't nest it in the pom.xml? So it goes in src/assembly/something.xml and gets referenced with a descriptorRef?
Can I code this as two relatively simple assemblies, of which one builds on the other (i.e. the .Zip assembly uses the .Jar assembly) or do I have to do everything in one assembly?
I'm starting to work with Maven but am not yet successfully thinking in Maven's terms.
Welcome on board, Carl! :D
I want to fire this assembly up from the command line (only), hence no need to tie to a phase (or goal? mojo?). Preferrably using either assembly:assembly or assembly:single.
Just to clarify: the build lifecycle itself is made of phases (compile, test, package, etc) and plugin goals (technically Mojos) are bound on phases. You then either invoke a phase... or just a specific plugin goal.
Do I need a custom assembly descriptor for this?
Well, since you want behavior that the pre-defined descriptors don't cover, yes. You'll even need two of them (of for the uberjar, one for the zip).
And is it true I can't nest it in the pom.xml? So it goes in src/assembly/something.xml and gets referenced with a descriptorRef?
Yes, that's true (descriptors use a custom format) and they usually go into src/main/assembly. And no, descriptorRef is for the built-in descriptors, you'll have to use descriptor here.
Can I code this as two relatively simple assemblies, of which one builds on the other (i.e. the .Zip assembly uses the .Jar assembly) or do I have to do everything in one assembly?
As hinted, you'll need two assembly descriptors. Let me help a bit...
Let's assume you have the following project structure:
$ tree .
.
├── pom.xml
└── src
├── main
│   ├── assembly
│   │   ├── jar.xml
│   │   └── zip.xml
│   ├── java
│   │   └── com
│   │   └── stackoverflow
│   │   └── App.java
│   └── resources
│   └── log4j.properties
└── test
└── java
└── com
└── stackoverflow
└── AppTest.java
Where the pom.xml contains the following configuration for the assembly plugin:
<project>
...
<dependencies>
...
</dependencies>
...
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/jar.xml</descriptor>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
The descriptor for the "filtered" uberjar (jar.xml) looks like this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
What this descriptor does is (in short):
include the dependencies, unpack them, but exclude the project itself (yes, this is counter intuitive but this weird default behavior has been kept for backward compatibility)
include the project files but exclude some of them.
And the descriptor for the zip (zip.xml) looks like this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory/>
<includes>
<include>log4j.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory/>
<includes>
<include>*-uberjar.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Which is (somehow) self explaining :)
it includes the configuration files (relatively to <directory>) at the root of the assembly
it includes the uberjar (relatively to <directory>) at the root of the assembly
Finally, just run mvn assembly:assembly (that's the goal intended to be used on the CLI).
I didn't (knowingly) include META-INF/maven/** in the assembly for the uberjar. Is there a simple way to prevent inclusion of these?
These are coming from the libraries that are unpacked. You can exclude them using unpackOptions. Here is a modified version of the jar.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>META-INF/maven/**</exclude>
</excludes>
</unpackOptions>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>

How can I tell jaxb / Maven to generate multiple schema packages?

Example:
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>schema1.xsd</include>
</schemaIncludes>
<generatePackage>schema1.package</generatePackage>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>schema2.xsd</include>
</schemaIncludes>
<generatePackage>schema2.package</generatePackage>
</configuration>
</plugin>
</plugins>
What happened:
Maven executes the the first plugin. Then deletes the target folder and creates the second package, which then is visible.
I tried to set target/somedir1 for the first configuration and target/somedir2 for the second configuration. But the behavior does not not change? Any ideas? I do not want to generate the packages directly in the src/main/java folder, because these packages are genereated and should not be mixed with manual created classes.
I had to specify different generateDirectory (without this, the plugin was considering that files were up to date and wasn't generating anything during the second execution). And I recommend to follow the target/generated-sources/<tool> convention for generated sources so that they will be imported in your favorite IDE automatically. I also recommend to declare several execution instead of declaring the plugin twice (and to move the configuration inside each execution element):
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<id>schema1-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>shiporder.xsd</include>
</schemaIncludes>
<generatePackage>com.stackoverflow.package1</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc1</generateDirectory>
</configuration>
</execution>
<execution>
<id>schema2-generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>books.xsd</include>
</schemaIncludes>
<generatePackage>com.stackoverflow.package2</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/xjc2</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
With this setup, I get the following result after a mvn clean compile
$ tree target/
target/
├── classes
│   ├── com
│   │   └── stackoverflow
│   │   ├── App.class
│   │   ├── package1
│   │   │   ├── ObjectFactory.class
│   │   │   ├── Shiporder.class
│   │   │   ├── Shiporder$Item.class
│   │   │   └── Shiporder$Shipto.class
│   │   └── package2
│   │   ├── BookForm.class
│   │   ├── BooksForm.class
│   │   ├── ObjectFactory.class
│   │   └── package-info.class
│   ├── dir1
│   │   └── shiporder.xsd
│   └── dir2
│   └── books.xsd
└── generated-sources
├── xjc
│   └── META-INF
│   └── sun-jaxb.episode
├── xjc1
│   └── com
│   └── stackoverflow
│   └── package1
│   ├── ObjectFactory.java
│   └── Shiporder.java
└── xjc2
└── com
└── stackoverflow
└── package2
├── BookForm.java
├── BooksForm.java
├── ObjectFactory.java
└── package-info.java
Which seems to be the expected result.
You can use also JAXB bindings to specify different package for each schema, e.g.
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" schemaLocation="book.xsd">
<jaxb:globalBindings>
<xjc:serializable uid="1" />
</jaxb:globalBindings>
<jaxb:schemaBindings>
<jaxb:package name="com.stackoverflow.book" />
</jaxb:schemaBindings>
</jaxb:bindings>
Then just use the new maven-jaxb2-plugin 0.8.0 <schemas> and <bindings> elements in the pom.xml. Or specify the top most directory in <schemaDirectory> and <bindingDirectory> and by <include> your schemas and bindings:
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>book/*.xsd</include>
<include>person/*.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
<include>book/*.xjb</include>
<include>person/*.xjb</include>
</bindingIncludes>
I think this is more convenient solution, because when you add a new XSD you do not need to change Maven pom.xml, just add a new XJB binding file to the same directory.
you should change that to define the plugin only once and do twice execution areas...like the following...and the generateDirectory should be set (based on the docs)..
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.7.1</version>
<executions>
<execution>
<id>firstrun</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>target/gen1</generateDirectory>
<schemaDirectory>src/main/resources/dir1</schemaDirectory>
<schemaIncludes>
<include>schema1.xsd</include>
</schemaIncludes>
<generatePackage>schema1.package</generatePackage>
</configuration>
</execution>
<execution>
<id>secondrun</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>target/gen2</generateDirectory>
<schemaDirectory>src/main/resources/dir2</schemaDirectory>
<schemaIncludes>
<include>schema2.xsd</include>
</schemaIncludes>
<generatePackage>schema2.package</generatePackage>
</configuration>
</execution>
</executions>
</plugin>
It seemed to me that you are fighting against single artifact rule of maven...may be you should think about this.
This can also be achieved by specifying stale file name for schemas and not clearing output directory. The default out put directory is automatically included in classpath which is little convenient. If we specify different output directory one has to take care of classpath to use this code in IDE. For example -
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<quiet>true</quiet>
<verbose>false</verbose>
<clearOutputDir>false</clearOutputDir>
<readOnly>true</readOnly>
<arguments>-mark-generated</arguments>
</configuration>
<executions>
<execution>
<id>reportingSchema</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schema/r17/schemaReporting</schemaDirectory>
<schemaIncludes>
<include>OCISchemaReporting.xsd</include>
</schemaIncludes>
<packageName>com.broadsoft.oci.r17.reporting</packageName>
<staleFile>${build.directory}/generated-sources/.jaxb-staleFlag-reporting</staleFile>
</configuration>
</execution>
<execution>
<id>schemaAS</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/schema/r17/schemaAS</schemaDirectory>
<schemaIncludes>
<include>OCISchemaAS.xsd</include>
</schemaIncludes>
<packageName>com.broadsoft.oci.r17.as</packageName>
<staleFile>${build.directory}/generated-sources/.jaxb-staleFlag-as</staleFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Source:Generating Code with JAXB Plugin
i have solved with:
<removeOldOutput>false</removeOldOutput>
<clearOutputDir>false</clearOutputDir>
<forceRegenerate>true</forceRegenerate>
add this to each configuration ;)
This is fixed in version 1.6 of the plugin.
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
Quick note though, I noticed that the first iteration output was being deleted. I fixed it by adding the following to each of the executions.
<removeOldOutput>false</removeOldOutput>
<clearOutputDir>false</clearOutputDir>
Here is my full working example with each iteration outputting correctly. BTW I had to do this due to a duplicate namespace problem with the xsd's I was given. This seems to resolve my problem.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>submitOrderRequest</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<schemaDirectory>src/main/resources/xsd/</schemaDirectory>
<!-- <schemaFiles>getOrderStatusResponse.xsd,quoteShippingRequest.xsd,quoteShippingResponse.xsd,submitOrderRequest.xsd,submitOrderResponse.xsd</schemaFiles> -->
<schemaFiles>submitOrderRequest.xsd</schemaFiles>
<bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>
<bindingFiles>submitOrderRequest.xjb</bindingFiles>
<removeOldOutput>false</removeOldOutput>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>submitOrderResponse</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<schemaDirectory>src/main/resources/xsd/</schemaDirectory>
<!-- <schemaFiles>getOrderStatusResponse.xsd,quoteShippingRequest.xsd,quoteShippingResponse.xsd,submitOrderRequest.xsd,submitOrderResponse.xsd</schemaFiles> -->
<schemaFiles>submitOrderResponse.xsd</schemaFiles>
<bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>
<bindingFiles>submitOrderResponse.xjb</bindingFiles>
<removeOldOutput>false</removeOldOutput>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
The following works for me, after much trial
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>xjc1</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.mycompany.clientSummary</packageName>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/wsdl/GetClientSummary.wsdl</source>
</sources>
<outputDirectory>target/generated-sources/xjb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>xjc2</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.mycompany.wsclient.employerProfile</packageName>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/wsdl/GetEmployerProfile.wsdl</source>
</sources>
<outputDirectory>target/generated-sources/xjb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>xjc3</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>com.mycompany.wsclient.producersLicenseData</packageName>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/wsdl/GetProducersLicenseData.wsdl</source>
</sources>
<outputDirectory>target/generated-sources/xjb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
I encountered a lot of problems when using jaxb in Maven but i managed to solve your problem by doing the following
First create a schema.xjc file
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="YOUR_URL?wsdl#types?schema1">
<jaxb:schemaBindings>
<jaxb:package name="your.package.name.schema1"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="YOUR_URL??wsdl#types?schema2">
<jaxb:schemaBindings>
<jaxb:package name="your.package.name.schema2"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
The package name can be anything you want it to be, as long as it doesn't contain any reserved keywords in Java
Next you have to create the wsimport.bat script to generate your packaged and code at the preferred location.
cd C:\YOUR\PATH\TO\PLACE\THE\PACKAGES
wsimport -keep -verbose -b "C:\YOUR\PATH\TO\schema.xjb" YOUR_URL?wsdl
pause
If you do not want to use cd, you can put the wsimport.bat in "C:\YOUR\PATH\TO\PLACE\THE\PACKAGES"
If you run it without -keep -verbose it will only generate the packages but not the .java files.
The -b will make sure the schema.xjc is used when generating
There is another, a clear one (IMO) solution to this
There is a parameter called "staleFile" that uses as a flag to not generate stuff again. Simply alter it in each execution.

Maven Assembly plugin - Include repo jars

I have a multi module project and I am using assembly plugin to build a tar file. I have included all of my modules in assembly plugin using moduleSets tag.
<moduleSets>
<moduleSet>
<includes>
<include>module1</include>
<include>module2</include>
All of my module jars are assembled into a lib folder. I want to add mysql jar from my local maven repository to the same lib folder that contains all of my other modules. Adding local repository jars in moduleset doesnt seem to work.
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o 'mysql.mysql-connector-java:mysql-connector-java-version'
How can I include jars from maven repository.
I think that you need to declare your mysql jar in the includes subelement of a dependencySet.
Something like this:
<assembly>
<id>my-assembly</id>
...
<dependencySets>
<dependencySet>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>mysql:mysql-connector-java</include>
</includes>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
...
</assembly>
Refer to the Descriptor Format documentation and/or the chapter 12.5.4. dependencySets Section of the Maven Book for more details on this element.
I don't think you need to do anything special, just make sure mysql is listed as dependency in your project and it should work. Same applied to dependencies on modules - just list them as dependencies. Below is typical configuration of assembly plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
I had the same problem, and solved it by changing scope on pom dependency to compile.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>compile</scope>
</dependency>