A minimal Maven-based Java web application used for COMP0004. This project is aimed at junior developers who are learning how a basic Java web app is structured and how to run it locally.
- Java + Servlet API: A simple servlet handles HTTP requests.
- Maven: Manages dependencies, compilation, and packaging.
- WAR file: The web app is packaged as a
.warfor deployment to a servlet container (like Tomcat).
- JDK 8+ installed and
java/javacon your PATH - Maven 3+ installed and
mvnon your PATH
Check versions:
java -version
mvn -version.
βββ pom.xml # Maven build config
βββ src/
β βββ main/
β βββ java/ # Java source code
β βββ webapp/ # Web resources (WEB-INF, web.xml, etc.)
βββ target/ # Build output (generated)
From the project root:
mvn clean packageThis will:
- Compile your Java code
- Run tests (if any)
- Create a WAR file in
target/
The easiest way to run this project is through Maven using the embedded Tomcat setup. This is the preferred method because Maven will download and manage the required dependencies automatically.
From the project root:
mvn clean package
mvn exec:execThen open:
http://localhost:8080/
Tip: Keep the terminal running while the server is up. Stop it with
Ctrl+C.
This project packages a WAR, so you run it in a servlet container such as Tomcat.
- Build the WAR:
mvn clean package- Copy the WAR to Tomcatβs
webapps/folder:
cp target/*.war /path/to/tomcat/webapps/- Start Tomcat (example):
/path/to/tomcat/bin/startup.sh- Open your browser:
http://localhost:8080/
Tip: Tomcat will deploy the WAR automatically when it appears in
webapps/.
mvn cleanβ remove old build outputmvn compileβ compile the code onlymvn testβ run testsmvn packageβ build the WAR
- Port already in use: Another service is using
8080. Stop it or change Tomcatβs port. - Missing Java: Ensure
JAVA_HOMEis set andjava -versionworks. - Maven not found: Install Maven and ensure
mvnis on your PATH.
- Add another servlet and map it in
web.xml - Explore request parameters and responses
- Try a simple HTML form and process it in a servlet
If youβre new to Java web apps, focus on the build/run cycle first: edit β mvn package β deploy WAR β refresh browser.