0

I want to create a tool based on maven, when i add a dependency to pom.xml, i want to automatically extract some files from the download jar file and copy them to another folder. is it possible to extend the maven dependency plugin? Any advice is appreciated.

Sam K
  • 47
  • 2
  • 6

1 Answers1

2

You can create folders contains of all dependencies with Maven Dependency Plugin and simple sample added below

         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!-- configure the plugin here -->
                        </configuration>
                    </execution>
                </executions>
            </plugin>

and you can copy jar files to desire folder with following plugin

http://evgeny-goldin.com/wiki/Copy-maven-plugin

this is a simple sample that you can use for copying files from dependency folder in target to another folder

        <plugin>
            <!-- download from here
             http://evgeny-goldin.org/artifactory/repo/com/goldin/plugins/maven-copy-plugin/0.2.3.8-beta-9/
             -->
            <groupId>com.goldin.plugins</groupId>
            <artifactId>maven-copy-plugin</artifactId>
            <version>0.2.3.8-beta-9</version>
            <executions>
                <execution>
                    <id>create-archive</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <!-- ~~~~~~~~~~~~~~ -->
                            <!-- Copy resources -->
                            <!-- ~~~~~~~~~~~~~~ -->
                            <resource>
                                <targetPath>c:/YOUR_NEW_FOLDER/</targetPath>
                                <directory>${project.basedir}/target/dependency/</directory>
                                <includes>
                                    <include>*.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>


                </execution>

            </executions>
        </plugin>
Ashkan
  • 320
  • 2
  • 17
  • first plugin execute in package phase and second plugin execute in install phase, you can change these phase based on your requirements – Ashkan Jul 02 '12 at 06:24
  • Thanks, but i need to extract some files from the dependency jar file. like /meta-info/xxx. not copy the jar files. – Sam K Jul 02 '12 at 09:41
  • for this purpose you can use first plugin, follow these links http://maven.apache.org/plugins/maven-dependency-plugin/ and http://stackoverflow.com/questions/5559519/maven-extract-files-from-jar – Ashkan Jul 03 '12 at 06:58