maven java webapp project example

Maven java webapp project:

The archetype:generate command is used to create the simple maven java web project. First we have to navigate the terminal (*uix or Mac) or command prompt (Windows) to the folder where we want to create the Java web project.

Syntax:

mvn archetype:generate -DgroupId=groupid -DartifactId=project-name   
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=booleanValue

Example:

mvn archetype:generate -DgroupId=com.tutorialspointexamples -DartifactId= MavenWebProject  
-DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Generated directory structure:

|____MavenWebProject
| |____pom.xml
| |____src
| | |____main
| | | |____resources
| | | |____webapp
| | | | |____index.jsp
| | | | |____WEB-INF
| | | | | |____web.xml

Auto created index.jsp:

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

Auto created web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>

Auto created pom.xml:

<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.tutorialspointexamples</groupId>
  <artifactId>MavenWebProject</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>MavenWebProject 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>MavenWebProject</finalName>
  </build>
</project>


Please follow and like us:
Content Protection by DMCA.com