Maven - Replace the file in the bank

I want to replace an element in an existing jar / zip file by doing a maven build. What is the easiest way to achieve this? Thank.

+3
source share
2 answers

My favorite for this kind of task is maven-antrun-plugin , which brings you full ant functionality.

You can use it as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
      <execution>
        <id>repack</id>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <target>
            <!-- note that here we reference previously declared dependency -->
            <unzip src="${org.apache:common-util:jar}" dest="${project.build.directory}/tmp"/>
            <!-- now do what you need to any of unpacked files under target/tmp/ -->
            <zip basedir="${project.build.directory}/tmp" destfile="${project.build.directory}/common-util-modified.jar"/>
            <!-- now the modified jar is available  -->
          </target>
        </configuration>
      </execution>
    </executions>
  </plugin>

But remember - never modify files in the local repository - in this example that points to ${org.apache:common-util:jar}. This will affect your future builds of all your projects on the same computer (= against the same local repo).

Such assemblies are also not reproducible (or difficult to reproduce) on other machines.

+7
+3

All Articles