TrueZIP Maven Plugin

This plugin uses TrueZIP which treats archives as a virtual file systems. Each archive file is considered as a directory of a file system.

Similar to assembly and clean plugins, FileSet is used extensively to manipulate file system type actions.

The following contains brief examples on how to use the truezip goals.

Remove

The remove goal can remove files from an existing archive. The below example show how to remove any file with pom.properies under maven directory of the $archive

  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>remove-a-file</id>
            <goals>
              <goal>remove</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <fileset>
                <!-- note how the archive is treated a normal file directory -->
                <directory>${archive}/META-INF/maven</directory>
                <includes>
                  <include>**/pom.properties</include>
                </includes>
              </fileset>
            </configuration>
          </execution>
          [...]
        </executions>
      </plugin>
      [...]
    </plugins>
  </build>
  
  <properties>
    <archive>path.to.a.archive</archive>
  </properties>

Copy

The copy goal can copy files in and out of the archive. The bellow example shows multiple executions:

  • Copy files from the archive to a real file system with option to rename the file on the fly. This is similar maven-assembly-plugin's files configuration.
  • Copy files from the archive to a real file system using FileSet interface.
  • Copy files from the real file system to the archive.
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>copy-out-files</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <files>
                <file>
                  <source>${archive}/META-INF/maven/${project.groupId}/${project.artifactId}/pom.properties</source>
                  <outputDirectory>${project.build.directory}/copy-file</outputDirectory>
                </file>
                <file>
                  <source>${archive}/META-INF/maven/${project.groupId}/${project.artifactId}/pom.xml</source>
                  <outputDirectory>${project.build.directory}/copy-file</outputDirectory>
                  <destName>pom.with.xml.extension</destName>
                </file>
              </files>
            </configuration>
          </execution>

          <execution>
            <id>copy-out-fileset</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <fileset>
                <directory>${archive}</directory>
                <excludes>
                  <exclude>**/pom.properties</exclude>
                </excludes>
                <outputDirectory>${project.build.directory}/copy-fileset</outputDirectory>
              </fileset>
            </configuration>
          </execution>

          <execution>
            <id>copy-into</id>
            <goals>
              <goal>copy</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <fileset>
                <directory>${basedir}</directory>
                <includes>
                  <include>*</include>
                </includes>
                <outputDirectory>${archive}/copy-into</outputDirectory>
              </fileset>
            </configuration>
          </execution>
          
      </plugin>
      [...]
    </plugins>
  </build>
  
  <properties>
    <archive>path.to.a.archive</archive>
  </properties>

Pack/unpack from command line

Use cp goal to copy an archive/directory to another archive/directory.

  • The following example shows how to unpack an archive to a directory
    mvn truezip:cp -Dfrom=apache-maven-2.2.1-bin.tar.gz -Dto=.
    
  • The following example shows how to pack a directory to an archive
    mvn truezip:cp -Dfrom=apache-maven-2.2.1 -Dto=apache-maven-2.2.1.zip
    
  • The following example shows how to transfer an archive to another archive
    mvn truezip:cp -Dfrom=apache-maven-2.2.1-bin.tar.gz -Dto=apache-maven-2.2.1-bin.zip
    

Move

The move goal can move a file in, out, or with in the archive. The below examples who to move an archive's file to another location in the archive. Note that the locacation can be outside for archive as well.

  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>truezip-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>move-a-file</id>
            <goals>
              <goal>move</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <!-- move a archive file to another directory in the same archive -->
              <from>${archive}/META-INF/MANIFEST.MF</from>
              <to>${archive}/META-INF2/MANIFEST.MF</to>
              
              <!-- use this if you want to move it out of the archive -->
              <!--to>${project.build.directory}/MANIFEST.MF</to-->
            </configuration>
          </execution>
          [...]
        </executions>
      </plugin>
      [...]
    </plugins>
  </build>
  
  <properties>
    <archive>path.to.a.archive</archive>
  </properties>