Create maven web project in eclipse step by step

Learn to create maven web project in eclipse which we should be able to import on eclipse IDE for further development.

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

1. Create maven web project in eclipse

Run this maven command to create a maven web project named ‘demoWebApplication‘. Maven archetype used is ‘maven-archetype-webapp‘.

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

This will create maven web project structure and web application specific files like web.xml.

create-web-project-using-maven-1844893

2. Convert to eclipse dynamic web project

To Convert created maven web project to eclipse dynamic web project, following maven command needs to be run.

$ mvn eclipse:eclipse -Dwtpversion=2.0

convert-to-eclipse-webproject-9798545

Please remember that adding “-Dwtpversion=2.0” is necessary, otherwise using only “mvn eclipse:eclipse” will convert it to only normal Java project (without web support), and you will not be able to run it as web application.

3. Import web project in Eclipse

  1. Click on File menu and click on Import option.
    import-project-menu-9106164
  2. Now, click on “Existing project..” in general section.
    existing-project-menu-9473492
  3. Now, browse the project root folder and click OK. Finish.
    browse-project-menu-2890673
  4. Above steps will import the project into eclipse work space. You can verify the project structure like this.
    project-created-success-4773138

In this maven tutorial, we learned how to create maven dynamic web project in eclipse. In this example, I used eclipse oxygen. You may have different eclipse version but the steps to follow will be same.

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

18 thoughts on “Create maven web project in eclipse step by step”

  1. Hi Lokhesh,

    I am getting this error

    NFO] Generating project in Interactive mode
    ARNING] No archetype found in remote catalog. Defaulting to internal catalog
    NFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
    oose archetype:
    internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.)
    internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.)
    internal -> org.apache.maven.archetypes:maven-archetype-plugin (An archetype which contains a sample Maven plugin.)
    internal -> org.apache.maven.archetypes:maven-archetype-plugin-site (An archetype which contains a sample Maven plugin site.
    This archetype can be layered upon an existing Maven plugin project.)
    internal -> org.apache.maven.archetypes:maven-archetype-portlet (An archetype which contains a sample JSR-268 Portlet.)
    internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
    internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.)
    internal -> org.apache.maven.archetypes:maven-archetype-site (An archetype which contains a sample Maven site which demonstrates
    some of the supported document types like APT, XDoc, and FML and demonstrates how
    to i18n your site. This archetype can be layered upon an existing Maven project.)
    internal -> org.apache.maven.archetypes:maven-archetype-site-simple (An archetype which contains a sample Maven site.)
    : internal -> org.apache.maven.archetypes:maven-archetype-webapp (An archetype which contains a sample Maven Webapp project.)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 7: -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
    oose archetype:
    Your filter doesn’t match any archetype (hint: enter to return to initial list)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 2
    oose archetype:
    Your filter doesn’t match any archetype (hint: enter to return to initial list)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
    choose archetype:
    Your filter doesn’t match any archetype (hint: enter to return to initial list)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1.2
    oose archetype:
    Your filter doesn’t match any archetype (hint: enter to return to initial list)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : mvn eclipse:eclipse -Dwtpversion=2.0
    oose archetype:
    Your filter doesn’t match any archetype (hint: enter to return to initial list)
    oose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :

    Reply
  2. 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?

    Thanks,
    Vineet Kumar

    Reply
  3. 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.

    Reply
  4. 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?

    Reply
  5. 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.

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

      Reply
  6. 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

    Reply
  7. 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.1.000.200.1” etc..

    Reply
  8. 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
    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

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.