This is a simple Maven-based web application that demonstrates how to create and serve multiple pages using servlets. It includes three servlets, each serving different content, along with a RESTful API that returns data in JSON format.
Make sure you have the following installed:
- Java 8+
- Apache Maven
- An IDE (optional) such as IntelliJ IDEA, Eclipse, or Visual Studio Code.
-
Clone this repository to your local machine:
git clone https://github.com/srtimsina/hello-devops.git cd hello-devops -
Build the project using Maven:
mvn clean package
This will compile the code and generate a
hello-devops.warfile in thetarget/directory.
To run the application, you need to deploy it to a Servlet container, such as Apache Tomcat.
-
Deploying to Apache Tomcat:
- Copy the techaxis-webapp.war file from the target/ folder to your webapps/ directory in Tomcat.
- Start Tomcat by running the bin/startup.sh script (on Linux/Mac) or bin/startup.bat (on Windows).
-
Access the application: Open a browser and go to the following URL:
http://localhost:8080/hello-devops/
-
Hello Servlet: Displays a simple "Hello DevOps" message.
- Access it by visiting: http://localhost:8080/hello-devops/hello
-
Another Page Servlet: Displays another page with a different message.
- Access it by visiting: http://localhost:8080/hello-devops/anotherPage
-
API Servlet: Provides a JSON response with a message.
- Access it by visiting: http://localhost:8080/hello-devops/api/data
This project includes unit tests for each servlet. To run the tests, use the following Maven command:
mvn testThis will run all the JUnit tests, which include tests for the HelloServlet, AnotherPageServlet, and ApiServlet.
- Jakarta Servlet API: Required for servlet-based development.
- JUnit 5: Used for unit testing.
- Mockito: Used for mocking HTTP request and response objects.
- Gson: Used to convert Java objects to JSON format.