You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Narayanan Krishnamoorthy <kn...@yahoo-inc.com> on 2014/04/16 00:33:22 UTC

Generating Incorrect fat jar using maven-assembly-plugin in maven 2 with war packaging

Hi all,

I have a default pom file in our codebase that has "war" packaging.

We wanted to also generate a normal jar file (lean) and a fat jar with dependencies along with the war file in our build using the same pom.xml.

$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
Java version: 1.7.0_45
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x" version: "10.8.5" arch: "x86_64" Family: "mac"

We added the following plugins - maven–assembly-plugin to generate the far jar and maven-jar-plugin to generate the lean jar.


            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>assembly-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <executions>
              <execution>
                  <id>make-a-jar</id>
                  <phase>compile</phase>
                  <goals>
                      <goal>jar</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>

On mvn clean install,
It is generating all the 3 files : war, lean jar and far jar.

But the problem is the jar-with-dependencies (fat jar) generated is getting built in the wrong way. Its size becomes double that of the same jar built by using Maven 3.0.4 (yes, I tried upgrading the maven to 3.0.4 to test and everything is good
With maven 3).

The problem is only with maven 2 and to me it looks like since the overall packaging phase of the pom is war , it is generating a wrong fat jar using the maven-assembly-plugin.  Many src classes are missing from the fat jar.

Anyone faced this issue with maven 2 and war packaging. Maven 3.0.4 is just fine while generating the fat jar.

Does maven-assembly-plugin have some restrictions with maven 2 and war packaging ?

Is there an alternate plugin to generate a jar with dependencies other than maven-assembly-plugin ?

Thanks in advance
Narayanan


Re: Generating Incorrect fat jar using maven-assembly-plugin in maven 2 with war packaging

Posted by Baptiste Mathus <bm...@batmat.net>.
Hi,
Which version of the war plugin are you using?

BTW, you say it's OK with maven 3. Can't you just upgrade? Maven 2 is many
years old and has already been officially end of lifed (
http://maven.apache.org/maven-2.x-eol.html).

And about what you're doing: I'm unsure about why you seem to unnecessarily
try to package a fat jar although your target is a war?

Cheers
Le 16 avr. 2014 00:44, "Narayanan Krishnamoorthy" <kn...@yahoo-inc.com> a
écrit :

> Hi all,
>
> I have a default pom file in our codebase that has "war" packaging.
>
> We wanted to also generate a normal jar file (lean) and a fat jar with
> dependencies along with the war file in our build using the same pom.xml.
>
> $ mvn -version
> Apache Maven 2.2.1 (r801777; 2009-08-06 12:16:01-0700)
> Java version: 1.7.0_45
> Java home:
> /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
> Default locale: en_US, platform encoding: UTF-8
> OS name: "mac os x" version: "10.8.5" arch: "x86_64" Family: "mac"
>
> We added the following plugins - maven–assembly-plugin to generate the far
> jar and maven-jar-plugin to generate the lean jar.
>
>
>             <plugin>
>                 <artifactId>maven-assembly-plugin</artifactId>
>                 <configuration>
>                     <descriptorRefs>
>
> <descriptorRef>jar-with-dependencies</descriptorRef>
>                     </descriptorRefs>
>                 </configuration>
>                 <executions>
>                     <execution>
>                         <id>assembly-all</id>
>                         <phase>package</phase>
>                         <goals>
>                             <goal>single</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>
>       <plugin>
>           <groupId>org.apache.maven.plugins</groupId>
>           <artifactId>maven-jar-plugin</artifactId>
>           <executions>
>               <execution>
>                   <id>make-a-jar</id>
>                   <phase>compile</phase>
>                   <goals>
>                       <goal>jar</goal>
>                   </goals>
>               </execution>
>           </executions>
>       </plugin>
>
> On mvn clean install,
> It is generating all the 3 files : war, lean jar and far jar.
>
> But the problem is the jar-with-dependencies (fat jar) generated is
> getting built in the wrong way. Its size becomes double that of the same
> jar built by using Maven 3.0.4 (yes, I tried upgrading the maven to 3.0.4
> to test and everything is good
> With maven 3).
>
> The problem is only with maven 2 and to me it looks like since the overall
> packaging phase of the pom is war , it is generating a wrong fat jar using
> the maven-assembly-plugin.  Many src classes are missing from the fat jar.
>
> Anyone faced this issue with maven 2 and war packaging. Maven 3.0.4 is
> just fine while generating the fat jar.
>
> Does maven-assembly-plugin have some restrictions with maven 2 and war
> packaging ?
>
> Is there an alternate plugin to generate a jar with dependencies other
> than maven-assembly-plugin ?
>
> Thanks in advance
> Narayanan
>
>