views:

585

answers:

2

I have the multi module project this is the parent pom.

<?xml version="1.0" encoding="UTF-8"?>
<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"&gt;
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.atoms</groupId>
    <artifactId>atoms-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <url/>
    <modules>
        <module>atoms-persistence</module>
        <module>atoms-reglas</module>
     <module>atoms-webservice</module>
    </modules>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>

                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>assemble.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

In the project atoms-persitence I have the following files:

com.atoms.vo.*

com.atoms.service.*

com.atoms.dao.*

And in the atoms-reglas I have:

com.atoms.rules.*

how can I user the assembly plugin to make a jar that have only the classes in:

com.atoms.vo.* and com.atoms.rules.* ?

+2  A: 

Try something along these lines:

<assembly>
    <id>atoms</id>
    <formats>
     <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
     <fileSet>
      <directory>${basedir}/target/classes
      </directory>
      <outputDirectory>/</outputDirectory>
      <includes>
       <include>com/atoms/vo.**</include>
       <include>com/atoms/rules/**</include>
      </includes>
     </fileSet>
    </fileSets>
</assembly>
Boris Pavlović
A: 

First, explicitly specify that you want to use a version of the maven assembly plugin greater or equal to 2.2-beta-3 in your pom.xml (the includes/excludes of the unpackOptions element that you'll need later don't behave as expected in versions prior to 2.2-beta-3). I'm using version 2.2-beta-4 here:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <configuration>
    <descriptors>
      <descriptor>assemble.xml</descriptor>
    </descriptors>
  </configuration>
</plugin>

Then, declare a moduleSets with the modules of your choice and specify that you want to unpack their binary content using includes in your assembly.xml:

<assembly>
  <id>my-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
        <include>com.atoms:atoms-persistence</include>
        <include>com.atoms:atoms-reglas</include>
      </includes>
      <binaries>
        <outputDirectory>/</outputDirectory>
        <unpack>true</unpack>
        <unpackOptions>
          <includes>
            <include>com/atoms/vo/**</include>
            <include>com/atoms/rules/**</include>
          </includes>
        </unpackOptions>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

Finally, run the following command from the parent project:

mvn clean package assembly:assembly

This builds a target/atoms-parent-1.0-my-assembly.jar containing only the wanted classes.

Pascal Thivent
I tried this solution but it includes all the clases
atomsfat
Did you update your pom.xml to use version **2.2-beta-4** (or 2.2-beta-3) of the maven-assembly-plugin? I tested this before to post it. Please, provide the updated version of your pom.xml.
Pascal Thivent
Yes I try with 2.2-beta-4 <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-4</version> <configuration> <descriptors> <descriptor>assemble.xml</descriptor> </descriptors> </configuration> </plugin> </plugins>
atomsfat
Please update your question and provide more information about your setup and the actual result. As I said, I tested this and it's working fine with maven 2.2.1 and the maven-assembly-plugin 2.2-beta-4.
Pascal Thivent