Creating Simple j2ee web application in Maven

Step 1: Click on file and select new and click on Maven Project


Step 2: Select default and click on next


Step 2: Under filter Search for Archetype j2ee to create simple web app.
Eclipse will Retrieve available archetype


Step 3:To create simple webApp select webapp-j2ee


Step 4:Define group id and Artifact id(Project name) and click on finish


Step 5: Maven Automatically create Project Structure


index.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
 
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>

pom.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
 
  <groupId>com.spy</groupId>
  <artifactId>WebApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
 
  <name>WebApp</name>
  <url>http://maven.apache.org</url>
 
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.3</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.3</source>
          <target>1.3</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

 once you add dependency in pom.xml it will automatically download required jar file.

You can check your all dependency in maven website
Website link:https://mvnrepository.comworking fine.

Run index.jsp file


Step 7: Accessing index.jsp file


Leave a Reply

Your email address will not be published. Required fields are marked *