RSS Feed for This PostCurrent Article

Maven: JAR/WAR Final Name, Excluding JAR Files from WAR

Maven is a good build tool but sometimes it is quite confusing to use. I have encountered the followings

JAR/WAR file Final Name
By default the final JAR or WAR file generated is <project-name>-<version-number>.jar/war. At first to change it I used the following.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <configuration>
    	<finalName>myname</finalName>
    <configuration>
</plugin>

It works for JAR file but not for WAR file. I tried the following.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-alpha-1</version>
    <configuration>
        <finalName>myName</finalName>
    </configuration>
</plugin>

This does NOT work. At the end, the way which works for both JAR and WAR is


<build>
   <finalName>myName</finalName>
.......

.....

</build>  

To Exclude Unnecessary JAR files from WAR
I tried to generate the WAR file for my web application, and ended up with a lot of unwanted JAR files packaged together in the WAR file. To resolve this, first I tried to change the dependency to provided.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.3</version>
    <scope>provided</scope> 
</dependency>

This works but in the first place I do not need servlet-api-2.3.jar. It is packaged in the WAR because of transitive dependency. Finally I do it this way.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1-alpha-1</version>
    <configuration>
        <warSourceExcludes>WEB-INF/lib/servlet-api-2.3.jar&
          lt;/warSourceExcludes>
    </configuration>
</plugin>


Trackback URL


RSS Feed for This Post1 Comment(s)

  1. berkay | Jul 8, 2009 | Reply

    give it a try..

    your_war_name

    org.apache.maven.plugins
    maven-compiler-plugin
    2.0.2

    1.6
    1.6

    maven-war-plugin
    2.0.2

    true

1 Trackback(s)

  1. From links for 2008-10-17 « Object neo = neo Object | Oct 17, 2008

Sorry, comments for this entry are closed at this time.