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 !!

Lokesh has written 269 articles

I have 7 Years of rich experience in java technology. This has only increased my hunger to learn more. In this blog, i will be writing on different topics occasionally, and would love to engage in some meaningful serious discussions with you folks.

11 thoughts on “How to create a eclipse web application using maven

  1. Bibhash Roy says:

    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?

  2. chandu says:

    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. Lokesh says:

      “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.

  3. Manish says:

    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

  4. suparna says:

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

    Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-
    clean-plugin/2.5/maven-clean-plugin-2.5.pom
    [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

  5. Pingback: Fast, Easy Web Design! » Blog Archive » Web Applications BrainyPro

Want to ask any question? Or suggest anything?