Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove file from dependency jar using maven

Tags:

maven-2

I am trying to remove a file from a dependency jar that I am including in my war file in maven. I am deploying the war to JBoss 5.1 and the jar in question contains a persistence.xml file that I don't want.

Here's what is going on:

my-webapp.war
|
`-- WEB-INF
    |
    `-- lib
        |
        `-- dependency.jar
            |
            `-- META-INF
                |
                `-- persistence.xml

When I am building my war, I want to remove persistence.xml Any one have any idea if this can be done easily?

like image 544
Matt Campbell Avatar asked May 13 '10 22:05

Matt Campbell


2 Answers

You can achieve this with the TrueZIP Maven Plugin.

This should work for your use case:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>truezip-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <id>remove-a-file-in-sub-archive</id>
            <goals>
                <goal>remove</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <fileset>
                    <directory>target/my-webapp.war/WEB-INF/lib/dependency.jar/META-INF</directory>
                    <includes>
                        <include>persistence.xml</include>
                    </includes>
                </fileset>
            </configuration>
        </execution>
    </executions>
</plugin>

Also see the examples.

like image 74
Andrea Avatar answered Sep 19 '22 12:09

Andrea


Not available out of the box AFAIK, you'll have to use the Maven AntRun plugin after package to do a few dirty things:

  • unzip the war in a temp directory
  • unzip the dependency in another temp directory
  • delete the file from the dependency
  • zip the temp directory of the dependency back into a jar
  • move the dependency back in the temp directory of the war
  • zip the temp directory of the webapp back into a war
  • delete the temp directory of the dependency
  • delete the temp directory of the webapp

The following resources might help

  • ant task to remove files from a jar
  • RE: Removing a file from .jar file

Now, if the problem is that JBoss is deploying the persistence unit defined in the persistence.xml (and you don't want that), there might be a better solution. It seems that you can declare files to ignore in a jboss-ignore.txt file, for example:

WEB-INF/lib/dependency.jar/META-INF/persistence.xml

The feature is there, but I've never used it.

See

  • Excluding persistence.xml from deployment
  • JBoss5 custom metadata files
like image 23
Pascal Thivent Avatar answered Sep 19 '22 12:09

Pascal Thivent