2

I have an application that is built via Maven, the end result being a .war file - which works all well and good.

It pulls a number of dependencies from a repository during the build and uses them within the application. One of these dependencies is a jar file, within the jar file is a zip file and within that zip is one file that I want to remove.

Using maven-antrun-plugin i have managed to move that jar to a tmp location from TARGET and explode the jar file. I then explode the zip file, remove the offending file, package everything back together and put it in TARGET once more.

The problem is that this happens after the WAR file is built so the new jar that i put back into TARGET is not used. I know this is because it has already been packaged so I tried to alter the JAR before this stage using similar to below (Found via: Run an ant task in maven build phase before war is packaged?)

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>package</phase>
            <inherited>false</inherited>
            <configuration>
                <target>
           <-- JAR was modified in here -->
                </target>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <!-- First step is to disable the default-war build step. -->
            <id>default-war</id>
            <phase>none</phase>
        </execution>
        <execution>
            <!-- Second step is to create an exploded war. Done in prepare-package -->
            <id>war-exploded</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>exploded</goal>
            </goals>
        </execution>
        <execution>
            <!-- Last step is to make sure that the war is built in the package phase -->
            <id>custom-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
        </execution>
    </executions>
</plugin>

It successfully runs the ant plugin after the war is exploded but before it has been packaged and therefore it cannot find any file that I reference in the TARGET directory?

Is there anyway to get it so that I can reference files in TARGET before the war is completed? If not can some suggest an alternative.

Note: I cannot upload a new dependency to the repo and/or use a local copy.

Community
  • 1
  • 1
ntb08117
  • 35
  • 4
  • You are using a jar file which contains a zip file ? Sounds wrong simply... – khmarbaise May 12 '17 at 07:38
  • @khmarbaise - it has been designed this way, not by myself. Regardless it is irrelevant, the question is can you alter any files that are placed in target and then use them when the war is compiled? – ntb08117 May 12 '17 at 07:45

0 Answers0