从 jar 中删除文件

Chr*_*ien 4 jar build maven

我的项目中有一个 jar 文件,我需要从中删除 persistence.xml

我发现了这个问题

使用 Maven 从依赖项 jar 中删除文件

但它似乎对我不起作用。

我将以下内容添加到我的 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>
Run Code Online (Sandbox Code Playgroud)

如果该 jar 名为 jarname.jar,我是否应该在路径中提及 .jar。我想不会。如果值得一提的话,我正在使用 Maven 2.2.1。

小智 5

您可以使用maven antrun插件

<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>
Run Code Online (Sandbox Code Playgroud)