How to Create a .war file using Eclipse Maven Plugin? Apache ‘maven-war-plugin’ usage

Last updated
App Shah

Crunchify » Java and J2EE Tutorials » How to Create a .war file using Eclipse Maven Plugin? Apache ‘maven-war-plugin’ usage


Maven is pretty amazing, isn’t it? Well – for me at least I love using Maven in my daily Java Development practice. Maven is nothing but a plugin execution framework; all work is done by plugins.

I’ve written number of Maven tutorials on Crunchify mainly on Maven Plugins. Here are couple of them:

==> Use maven-shade-plugin to create 1 single executable jar.

==> Use maven-resources, maven-dependency and maven-jar plugins to create executable jar file with all dependencies into 1 folder.

Now how about creating .war file instead of .jar file with Maven in Eclipse? This Maven Tutorial focuses on maven-war-plugin.

Our requirement here is to generate single .war file using Maven which you could run on Apache Tomcat or any other web container.

Let’s get started:

  1. Create Dynamic Web Project in Eclipse, i.e. CrunchifyTutorial
  2. Create simple .java file into your project, i.e.
  3. Convert Java Project into Maven project in Eclipse
  4. Add maven-war-plugin to pom.xml file
  5. Run command clean install to generate .war file


Create Dynamic Web Project in to Eclipse, i.e. CrunchifyTutorial


  • File ->
  • New ->
  • Other ->
  • Dynamic Web Project ->
  • Provide ProjectName (CrunchifyTutorial)
  • Click Finish


Convert Project to Maven Project. Follow these steps:


Create simple java file named

NOTE: In your dynamic web project you must have web.xml file which represents your servlet and servlet-mapping. You could use also Simple Spring MVC project too if you want for Step-3 here. If you don’t see web.xml then you could create one by following this tutorial.


 * @author

public class CrunchifyWarUsingMaven {
	public static void main(String[] args) {
				.println("Test.. Test by Crunchify.. \nThis is a simple tutorial on how to create .war file using Maven Plugin..");

Here is a project structure. You could ignore other files and folders from below diagram 🙂



Open your pom.xml file and update it with below code. Mainly look at line 7 and 20. We are packaging project as war using <packaging>war</packaging>.

<project xmlns="" xmlns:xsi=""


Now Right Click on Project -> Run-As ->Maven Build (Number 5).

Maven Build Option in Eclipse


Maven clean install on project.

Maven Clean Install Steps For Eclipse Web Project


Checkout your Build result in Eclipse console.

Maven war plugin - Building War Console Output


That’s it. Now get your .war file from /target directory and deploy into Apache Tomcat or any other Web Container.

13 thoughts on “How to Create a .war file using Eclipse Maven Plugin? Apache ‘maven-war-plugin’ usage”

  1. Hi
    After getting war file I deployed this in tomcat then while running this I am getting this error “the selection cannot be run on any server” any help please ? & I can’t see web.xml file in my war so I believe its might be cause but how it is missing while war file creation no Idea as I am new to maven? Thanks in advance.

    Venki Y.

  2. How do you include the resources folder in the war? I have deployed the war to the tomcat server, but when I press submit button on my web page, nothing happens. No console output in eclipse. I’m not sure whether the war isn’t deployed correctly or whether resources are missing? Help!

  3. Hi

    Thank you very much for Article , i have working in one project where after building war all dependencies(3rd Party Library) is going inside WARWEB-INFlib because of this WAR becoming very big and there are multiple WAR’s using same Libraries., please can you help with putting those JAR’s outside WAR while building using maven

    santhosh N

    • Hi Joe – can you please share your requirements in details? Didn’t get what you mean by “zip individual files”.


Leave a Comment