How to create a Web Application Project with Java/Maven/Jetty or Tomcat
In this article, we create a simple web application with the Maven Archetype plugin. We’ll run this web application in a Servlet container named Jetty, add some dependencies, write simple Servlets, and generate a WAR file. At the end of this article, you will also be able to deploy the service in Tomcat.
System requirements
Creating the Web Service Step by Step
This section explains how to create this simple web project from an EMPTY folder.
Creating the Simple Web Project
To create your web application
$ mvn archetype:generate -DgroupId=com.pengyifan.simpleweb \ -DartifactId=simple-webapp \ -Dpackage=com.pengyifan.simpleweb \ -DarchetypeArtifactId=maven-archetype-webapp \ -Dversion=1.0-SNAPSHOT \ -DinteractiveMode=false ... [INFO] BUILD SUCCESS
Once the Maven Archetype plugin creates the project, change the directory into the simple-webapp
directory and take a look at the pom.xml
. You should see the
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.pengyifan.simpleweb</groupId> <artifactId>simple-webapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>simple-webapp Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>simple-webapp</finalName> </build> </project>