Skip to content

Commit 615a317

Browse files
committed
mvn package working
1 parent 586765a commit 615a317

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Simple java project demos how to build a war file to be deployed on a Tomcat ser
1010

1111
## Initial Generation
1212

13-
The initial files and project structure was generated with the `mvn archetype:generate` command. Note, you do not have to run the command it is just noted here for posterity.
13+
The initial files and project structure was generated with the `mvn archetype:generate` command. Note, you do not have to run the command it is just noted here for posterity. More info: [Creating a webapp](https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/webapp.html) and [Introduction to the Standard Directory Layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html).
1414

1515
``` sh
1616
mvn archetype:generate \

pom.xml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,42 @@
55
<artifactId>demo</artifactId>
66
<packaging>war</packaging>
77
<version>1.0-SNAPSHOT</version>
8-
<name>demo Maven Webapp</name>
9-
<url>http://maven.apache.org</url>
8+
<name>Demo Maven Webapp</name>
9+
<url>https://github.com/tongueroo/demo-java</url>
10+
<build>
11+
<finalName>demo</finalName>
12+
<sourceDirectory>src</sourceDirectory>
13+
<plugins>
14+
<plugin>
15+
<artifactId>maven-compiler-plugin</artifactId>
16+
<version>3.7.0</version>
17+
<configuration>
18+
<source>1.8</source>
19+
<target>1.8</target>
20+
</configuration>
21+
</plugin>
22+
<plugin>
23+
<artifactId>maven-war-plugin</artifactId>
24+
<version>3.0.0</version>
25+
</plugin>
26+
</plugins>
27+
</build>
1028
<dependencies>
1129
<dependency>
1230
<groupId>junit</groupId>
1331
<artifactId>junit</artifactId>
1432
<version>3.8.1</version>
1533
<scope>test</scope>
1634
</dependency>
35+
<dependency>
36+
<groupId>log4j</groupId>
37+
<artifactId>log4j</artifactId>
38+
<version>1.2.17</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>javax.servlet</groupId>
42+
<artifactId>javax.servlet-api</artifactId>
43+
<version>3.1.0</version>
44+
</dependency>
1745
</dependencies>
18-
<build>
19-
<finalName>demo</finalName>
20-
</build>
2146
</project>

src/main/java/Hello.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Import required java libraries
2+
import java.io.*;
3+
import javax.servlet.*;
4+
import javax.servlet.http.*;
5+
6+
// Extend HttpServlet class
7+
public class Hello extends HttpServlet {
8+
9+
private String message;
10+
11+
public void init() throws ServletException {
12+
// Do required initialization
13+
message = "Hello World";
14+
}
15+
16+
public void doGet(HttpServletRequest request, HttpServletResponse response)
17+
throws ServletException, IOException {
18+
19+
// Set response content type
20+
response.setContentType("text/html");
21+
22+
// Actual logic goes here.
23+
PrintWriter out = response.getWriter();
24+
out.println("<h1>" + message + "</h1>");
25+
}
26+
}

src/main/webapp/WEB-INF/web.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,23 @@
33
"http://java.sun.com/dtd/web-app_2_3.dtd" >
44

55
<web-app>
6-
<display-name>Archetype Created Web Application</display-name>
6+
<display-name>demo java web app</display-name>
7+
<welcome-file-list>
8+
<welcome-file>index.html</welcome-file>
9+
<welcome-file>index.htm</welcome-file>
10+
<welcome-file>index.jsp</welcome-file>
11+
<welcome-file>default.html</welcome-file>
12+
<welcome-file>default.htm</welcome-file>
13+
<welcome-file>default.jsp</welcome-file>
14+
</welcome-file-list>
15+
16+
<servlet>
17+
<servlet-name>Hello</servlet-name>
18+
<servlet-class>Hello</servlet-class>
19+
</servlet>
20+
<servlet-mapping>
21+
<servlet-name>Hello</servlet-name>
22+
<url-pattern>/Hello</url-pattern>
23+
</servlet-mapping>
24+
725
</web-app>

0 commit comments

Comments
 (0)