unpack dependency and repack classes using maven?

Posted by u123 on Stack Overflow See other posts from Stack Overflow or by u123
Published on 2012-10-30T15:36:30Z Indexed on 2012/10/30 17:01 UTC
Read the original article Hit count: 204

Filed under:
|

I am trying to unpack a maven artifact A and repack it into a new jar file in the maven project B.

Unpacking class files from artifact A into:

    <my.classes.folder>${project.build.directory}/staging</my.classes.folder>

works fine using this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.test</groupId>
                                <artifactId>mvn-sample</artifactId>
                                <version>1.0.0-SNAPSHOT</version>
                                <type>jar</type>
                                <overWrite>true</overWrite>
                                <outputDirectory>${my.classes.folder}</outputDirectory>
                                <includes>**/*.class,**/*.xml</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

In the same pom I now want to generate an additional jar containing the classes just unpacked:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                    <classesdirectory>${my.classes.folder}</classesdirectory>
                        <classifier>sample</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>

A new jar is created but it does not contain the classes from the:

 ${my.classes.folder}

its simply a copy of the default project jar. Any ideas?

I have tried to follow this guide:

http://jkrishnaraotech.blogspot.dk/2011/06/unpack-remove-some-classes-and-repack.html

but its not working.

© Stack Overflow or respective owner

Related posts about maven

Related posts about jar