25
votes

I package my Maven-based Spring app with:

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.

enter image description here

Here is extracted 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"

6
Could you please write here the output for the "mvn -version" ?user1352498
thanks. I will search for it too. I run mvn version 3 here and I had the same behaviour. double files inside the jar.user1352498
Same here! I've also found these files duplicated few time using same Maven version. It didn't actually fuss me, because everything works fine, but it's really weird.Michał Kalinowski

6 Answers

17
votes

Add

<build>
   <plugins>
     <plugin>
       <artifactId>maven-jar-plugin</artifactId>
       <configuration>
         <archive>
           <addMavenDescriptor>false</addMavenDescriptor>
         </archive>
       </configuration>
     </plugin>
   </plugins>
</build>

to your pom.xml

14
votes

It seems like this is a somewhat common problem that arises from a conflict in Eclipse, especially with the m2e-wtp integration.

Some people are indicating that it can be fixed by including clean in the list of goals to run, e.g. mvn clean package.

Also try to update your m2e installation and make sure you don't have multiple versions of m2e or m2eclipse (the pre-Indigo version) installed.

Some references to other people facing this problem:

6
votes

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.

0
votes

Follow up to @Dan's work around:

I tried your solution and it appears to 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.

If the polling is on - you "fail-fast". If it's off you can fail at arbitrary times in future builds.

0
votes

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.

-5
votes

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 section of the maven getting started guide.