java Maven 在 jar 中生成重复的 pom.xml 和 pom.properties 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10308916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven generates duplicate pom.xml and pom.properties files in a jar
提问by bnguyen82
I package my Maven-based Spring app with:
我将基于 Maven 的 Spring 应用程序打包为:
mvn install-DskipTests -Peverything.
And something strange arises. In META-INF of generated jar, I find duplicate pom.xml and pom.properties files. Can someone explain it? Thanks.
奇怪的事情出现了。在生成的 jar 的 META-INF 中,我发现重复的 pom.xml 和 pom.properties 文件。有人可以解释一下吗?谢谢。
Here is extracted pom.xml
这里是提取的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.xyz</groupId>
<artifactId>migrate-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>migrate-app</name>
<url>http://maven.apache.org</url>
<dependencies>
..
</dependencies>
<profiles>
<profile>
<id>everything</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Output for command:
命令的输出:
mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700) Maven home: C:\apache-maven-3.0.4\bin.. Java version: 1.6.0_30, vendor: Sun Microsystems Inc. Java home: C:\Program Files (x86)\Java\jdk1.6.0_30\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700) Maven 主页:C:\apache-maven-3.0.4\bin.. Java 版本:1.6.0_30,供应商:Sun Microsystems Inc . Java 主页:C:\Program Files (x86)\Java\jdk1.6.0_30\jre 默认语言环境:en_US,平台编码:Cp1252 操作系统名称:“windows 7”,版本:“6.1”,arch:“x86”,家庭:“窗户”
回答by besc
Add
添加
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
to your pom.xml
到你的 pom.xml
回答by nwinkler
It seems like this is a somewhat common problem that arises from a conflict in Eclipse, especially with the m2e-wtpintegration.
这似乎是 Eclipse 中的冲突引起的一个有点常见的问题,尤其是与m2e-wtp集成。
Some people are indicating that it can be fixed by including cleanin the list of goals to run, e.g. mvn clean package
.
有些人表示可以通过在要运行的目标列表中包含clean来修复它,例如mvn clean package
。
Also try to update your m2einstallation and make sure you don't have multiple versions of m2eor m2eclipse(the pre-Indigo version) installed.
还要尝试更新您的m2e安装,并确保您没有安装多个版本的m2e或m2eclipse(Indigo 之前的版本)。
Some references to other people facing this problem:
对面临此问题的其他人的一些参考:
回答by Don
I know this issue is a bit old, but I thought I'd share an obscure bit of information on this subject. I was running across the same issue, and I found that when I ran maven with Eclipse open, AND my workspace preferences were set to refresh the workspace using native hooks or polling, the extra pom.xml and pom.properties files were added by eclipse! Closing eclipse or removing the refresh workspace option solved the problem for me. This was a hard one to track down, so hopefully someone else will benefit from this.
我知道这个问题有点老,但我想我会分享关于这个主题的一些晦涩的信息。我遇到了同样的问题,我发现当我在 Eclipse 打开的情况下运行 maven,并且我的工作区首选项设置为使用本机挂钩或轮询刷新工作区时,eclipse 添加了额外的 pom.xml 和 pom.properties 文件!关闭 eclipse 或删除刷新工作区选项为我解决了这个问题。这很难追踪,所以希望其他人能从中受益。
回答by rmp
Follow up to @Dan's work around:
跟进@Dan 的工作:
I tried your solution and it appearsto work -- at first blush. However, it's just delaying the eventual failure.
我尝试了您的解决方案,它似乎有效 - 乍一看。然而,这只是推迟了最终的失败。
It appears than anytime the workspace is refreshed the pom.xml and pom.properties files are created in the /classes directory. After that any later "package" goal will include the duplicate files in the .jar and thus break any later signing.
似乎任何时候刷新工作区都会在 /classes 目录中创建 pom.xml 和 pom.properties 文件。之后,任何以后的“包”目标都将包含 .jar 中的重复文件,从而破坏以后的任何签名。
If the polling is on - you "fail-fast". If it's off you can fail at arbitrary times in future builds.
如果投票正在进行 - 你“快速失败”。如果它关闭,您可能会在未来的构建中随时失败。
回答by Gopal Bairwa
You need to do "mvn clean" and the do "mvn package" after that or just do "mvn clean package". if "mvn clean" fails due to any reason and if you do "mvn package" after that , you will see this issue again.
你需要做“mvn clean”然后做“mvn package”或者只是做“mvn clean package”。如果“mvn clean”由于任何原因失败,并且在此之后执行“mvn package”,您将再次看到此问题。
回答by Raghuram
Not sure what you mean by duplicate
but the jar created by maven does come with pom.xml
and pom.properties
in META-INF
folder. See this sectionof the maven getting started guide.
不知道你的意思duplicate
,而是由行家创建的罐子来与不pom.xml
和pom.properties
的META-INF
文件夹中。请参阅maven 入门指南的这一部分。