Maven Web Application - Maven

How to manage a web based project using Maven?

Let’s learn about how to manage a web based project using Maven. Here you will learn how to create/build/deploy and run a web application.

Create Web Application

If you want to create a simple java web application, use maven-archetype-webapp plugin. Now open the command console, go to the C:\MVNdirectory and execute the following mvn command.
Let’s start processing and will create the complete web based java application project structure as follows –
Let’s go to C:/MVN directory. Find a java application project created, named trucks (as specified in artifactId) as specified in the following snapshot. Here’s the directory structure used for web applications −
Here Maven uses a standard directory layout. Let’s understand the following key concepts −
Sr.No. Folder Structure & Description


contains src folder and pom.xml.



contains index.jsp and WEB-INF folder.



contains web.xml



it contains images/properties files.


You can observe that Maven also created a sample JSP Source file.
Open C:\ > MVN > trucks > src > main > webapp > folder to see index.jsp with the following code –

Build Web Application

Now open the command console, go to the C:\MVN\trucks directory and execute the following mvn command.
Maven will start building the project.

Deploy Web Application

Now copy the trucks.war created in C:\ > MVN > trucks > target > folder to your webserver webapp directory and restart the webserver.

Test Web Application

Run the web-application using URL: http://<server-name>:<port-number>/trucks/index.jsp.
Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Maven Topics