【问题标题】:Removing file from jar从 jar 中删除文件
【发布时间】:2016-02-06 11:32:16
【问题描述】:

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

我发现了这个问题

Remove file from dependency jar using maven

但它似乎对我不起作用。

我在 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>

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

【问题讨论】:

  • 所以没有帮助。如果其中任何一个是选项,我会做的。我设法通过弄乱 Nexus 存储库并修改 jar 来对其进行排序。我不想这样做,因为我必须在稍后阶段将其改回,但我需要一个解决方案。

标签: maven jar build


【解决方案1】:

你可以使用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>

【讨论】:

    猜你喜欢
    • 2011-02-01
    • 2014-08-03
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多