How to create a eclipse web application using maven

In my previous post, we learned about creating a sample java project using maven using both modes i.e. interactive and non-interactive. In this project we will create a web application which we should be able to import on eclipse IDE.

To create eclipse supported web application, we will need to create first a normal maven we application and then we will make it compatible to eclipse IDE. Lets do it.

Step 1) Create a normal maven web application

Using below command, I am creating a web application named ‘demoWebApplication’. Archetype used is ‘maven-archetype-webapp‘.

mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=demoWebApplication
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

This will create a web application in your workspace.

create web project using maven

Step 2) Convert it to eclipse web application

To Convert it to eclipse web application, following command needs to be run.

mvn eclipse:eclipse -Dwtpversion=2.0

convert to eclipse webproject

Please remember that adding “-Dwtpversion=2.0” is necessary, otherwise using only “mvn eclipse:eclipse” will convert it to only normal java application, and you will not be able to run it as other eclipse web applications.

Step 3) Import the application in project

Click on File menu and click on Import option.

import project menuNow, click on “Existing project..” in general section.

Existing project menuNow, browse the project root folder and click OK. Finish.

Browse project menuAbove steps will import the project into eclipse work space. You can verify the project structure like this.

project created successHappy Learning !!

17 thoughts on “How to create a eclipse web application using maven”
  1. Hi Lokesh,

    Thanks for sharing this nice tutorials.
    I have a doubt about test folder which should be inside src folder. It is not there.
    Do I need to add this(i.e test) folder manually?

    Vineet Kumar

  2. Hi,

    I am biswajit , using selenium webdriver for testing. I want to convert my project to maven project. While doing so, it is showing an error.

    Can you pls guide me. I am seriously need help on Maven and configuring my pom.xml,

    Thanks in advance.

  3. I am getting the following error message (eclipse project with a red cross) after importing the project – “Java compiler level does not match the version of the installed Java project facet. – Unknown Faceted Project Problem (Java Version Mismatch)” Please help

    Surprising I am helios which is supposed to support WTP 3.2 but I used WTP 2.0 since my WTP plugin support upto 2.0 only….what is the source of problem?

  4. Hi Lokesh,
    while i run the -DarchetypeArtifactId=maven-archetype-webapp ” i am getting error like :’-DarchetypeArtifactId’ is not recognized as an internal or external command,
    operable program or batch file. please correct me.

    1. “mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=demoWebApplication -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false” is actually a single command. Remore any line break if there is any.

  5. Not able to successfully run the mvn command:
    Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate on project standalone-pom: The desired archtype does not exist

  6. Sir, what is the meaning of wtpversion?? why we are giving only 2.0 as the version value?? cant we give any other value like “ch.” etc..

  7. I am getting this error after entering mvn archetype:generate -DgroupId=com.howtodoinjava -DartifactId=demoWebApplication
    -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false in cmd

    [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
    n-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or on
    e of its dependencies could not be resolved: Failed to read artifact descriptor
    for org.apache.maven.plugins:maven-clean-plugin:jar:2.5

    Please solve this issue

Note:- In comment box, please put your code inside [java] ... [/java] OR [xml] ... [/xml] tags otherwise it may not appear as intended.

Leave a Reply

Your email address will not be published. Required fields are marked *