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 −
web-project-structure
Here Maven uses a standard directory layout. Let’s understand the following key concepts −
Sr.No. Folder Structure & Description
1

trucks

contains src folder and pom.xml.

2

src/main/webapp

contains index.jsp and WEB-INF folder.

3

src/main/webapp/WEB-INF

contains web.xml

4

src/main/resources

it contains images/properties files.

POM.xml

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.
web-page

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

Maven Topics