Chris O'Brien
Chris O'Brien

Reputation: 372

Removing file from jar

I have a jar file in a project that I need to remove a persistence.xml from

I found this questions

Remove file from dependency jar using maven

but it doesn't seem to have worked for me.

I added the following to my pom.xml

<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/app/WEB-INF/lib/jarname/META-INF</directory>
                                    <includes>
                                        <include>persistence.xml</include>
                                    </includes>
                                </fileset>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>

If the jar is called jarname.jar, should I mention the .jar in the path. I'd imagine not. I'm using Maven 2.2.1 if that's worth mentioning.

Upvotes: 4

Views: 3985

Answers (1)

DavoCoder
DavoCoder

Reputation: 872

You can use the maven antrun plugin

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
        <executions>
            <execution>
                <id>environment.replace.configuration</id>
                <phase>test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <delete
                                file="${project.build.outputDirectory}/WEB-INF/lib/jarname/META-INF/persistence.xml" />
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>

Upvotes: 5

Related Questions