tags:

views:

12

answers:

1

I'm trying to upgrade my project from using Maven 1 to Maven 2, but I'm having a problem with one of the goals. I have the following Maven 1 goal in my maven.xml file:

<goal name="jar:init">
    <ant:delete file="${basedir}/src/installpack.zip"/>
    <ant:zip destfile="${basedir}/src/installpack.zip"
             basedir="${basedir}/src/installpack" />

    <copy todir="${destination.location}">
        <fileset dir="${source.location}">
            <exclude name="installpack/**"/>
        </fileset>
    </copy>
</goal>

I'm unable to find a way to do this in Maven2, however.

Right now, the installpack directory is in the resources directory of my standard Maven2 directory structure, which works well since it just gets copied over. I need it to be zipped though.

I found this page on creating ant plugins: http://maven.apache.org/guides/plugin/guide-ant-plugin-development.html.

It looks like I could create my own ant plugin to do what I need. I was just wondering if there was a way to do it using only Maven2.

Any suggestions would be much appreciated.

Thanks, B.J.

+2  A: 

You don't need to create an ant plugin, use the Maven Antrun Plugin and Ant tasks to zip the installpack directory under target before the packaging. Declare the plugin like this in your pom:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase> <!-- a lifecycle phase --> </phase>
            <configuration>
              <tasks>

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

As documented, put your ant tasks in the <tasks> element and bind the plugin to a lifecycle phase, maybe the prepare-package phase (I guess jar:init was called before packaging).

Pascal Thivent
Thank you for the help. This works.
Benny