Maven - Maven Web Application - maven tutorial

What is Web Application?

  • Web application is a client-server software application in which the client (or user interface) runs in a web browser.Common web applications include webmail, online retail sales, online auctions, wikis, instant messaging services and many other functions.
  • learn maven tutorial - maven project - apache maven - web application deployment - Apache Maven example programs

    learn maven tutorial - maven project - web application deployment - Apache Maven example programs

  • We can create a simple maven web application example by executing the archetype: generate command of mvn tool.
  • To create a simple java project using maven, you need to open command prompt and run the archetype: generate command of mvn tool.
maven tutorial tags : apache maven , maven repository , maven central


  • The syntax to generate the project architecture is given below:
mvn archetype:generate 


  • The example to generate the project architecture is given below:
    • mvn archetype:generate -DgroupId=com.wikitechy -DartifactId=CubeGeneratorWeb
    • -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
  • Note: Here, we are using maven-archetype-webapp to create simple maven web application. if you use maven-archetype-quick start, it will generate a simple maven core project.
  • Now it will generate following code in the command prompt:


mvn archetype:generate -DgroupId=com.wikitechy -DartifactId=CubeGeneratorWe  
b -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false  
[INFO] Scanning for projects...  
[INFO] ------------------------------------------------------------------------  
[INFO] Building Maven Stub Project (No POM) 1  
[INFO] ------------------------------------------------------------------------  
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>  
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom <<  
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom --  
[INFO] Generating project in Batch mode  
n-archetype-webapp/1.0/maven-archetype-webapp-1.0.jar (4 KB at 3.8 KB/sec)  
n-archetype-webapp/1.0/maven-archetype-webapp-1.0.pom (533 B at 0.8 KB/sec)  
[INFO] -------------------------------------------------------------------------  
[INFO] Using following parameters for creating project from Old (1.x) Archetype:  
[INFO] -------------------------------------------------------------------------  
[INFO] Parameter: groupId, Value: com.wikitechy  
[INFO] Parameter: packageName, Value: com.wikitechy  
[INFO] Parameter: package, Value: com.wikitechy
[INFO] Parameter: artifactId, Value: CubeGeneratorWeb  
[INFO] Parameter: basedir, Value: D:\  
[INFO] Parameter: version, Value: 1.0-SNAPSHOT  
[INFO] project created from Old (1.x) Archetype in dir: D:\CubeGeneratorWeb  
[INFO] ------------------------------------------------------------------------  
[INFO] ------------------------------------------------------------------------  
[INFO] Total time: 10.273s  
[INFO] Finished at: Thu Dec 26 19:25:04 IST 2013  
[INFO] Final Memory: 10M/24M  
[INFO] ------------------------------------------------------------------------  
'cmd' is not recognized as an internal or external command,  
operable program or batch file.  

Generated Directory Structure

  • Now go to the current directory from where you have executed the mvn command.
  • For example: d:\CubeGeneratorWeb. You will see that a simple java project is created that has the following directory:
  • As you can see, there are created 3 files pom.xml, index.jsp and web.xml. Let's have a quick look at these files:

1.Automatically Generated pom.xml file

<project xmlns=""   
  <name>CubeGeneratorWeb Maven Webapp</name>  
maven tutorial tags : apache maven , maven repository , maven central

2.Automatically Generated index.jsp file

<h2>Hello World!</h2>  

3.Automatically Generated web.xml file

<!DOCTYPE web-app PUBLIC  
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"  
 "" >  
  <display-name>Archetype Created Web Application</display-name>  

Deploy and Run the Maven Web Project

  • Now you need to deploy the project on the server and access it by the following url:
    • http://<host-name>:<portnumber>/projectname,:
    • http://localhost:8888/CubeGeneratorWeb
maven tutorial tags : apache maven , maven repository , maven central


 Maven Web Project

Maven Webapp in Eclipse

You can import the maven web project in eclipse. To do so, perform following steps:

  • Open eclipse IDE
  • Import the maven project
  • File Menu -> Import -> Maven -> Existing Maven Projects
 Maven WebApp in Eclipse
  • Next -> Browse Project
 Maven Projects
  • Finish.

Run the maven web project

  • Right click on project -> Run As -> Run on Server

Directory Structure of Maven Webapp in Eclipse

 Maven Directory Structure

Wikitechy provides an indepth knowledge on the below maven tutorial items such as maven download , maven install , maven goals , maven build , maven commands , maven plugin , maven search , maven eclipse , maven deploy , eclipse maven , maven junit , maven java , hibernate maven , maven project , java maven , maven version , maven proxy , maven 2 , maven pom , maven eclipse plugin , maven java version , maven properties , maven install windows , how to create maven project in eclipse , eclipse maven plugin , maven dependencies , what is maven in java , maven apache , maven project structure , how to install maven in eclipse

Related Searches to Maven Web Application

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.