This document outlines the structure of the database application and explains how to run it.
Below is the directory structure for the project where the Tomcat 9.0 server will run directly from Eclipse IDE
bookup/ <-- Root directory of your Maven project
├── pom.xml <-- Maven configuration file
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── bookie/
│ │ │ ├── auth/ <-- Package for authentication and authorization
│ │ │ │ ├── AccessControlUtil.java
│ │ │ │ ├── IsAdmin.java
│ │ │ │ ├── IsAdminOrSameUser.java
│ │ │ │ ├── SameUser.java
│ │ │ │ └── UserContext.java
│ │ │ ├── bizlogic/ <-- Package for business logic (empty in the screenshot)
│ │ │ ├── dao/ <-- Package for Data Access Objects (DAOs)
│ │ │ ├── models/ <-- Package for models or data entities
│ │ │ └── servlet/ <-- Package for Servlets
│ │ │ ├── GetBooks.java
│ │ │ ├── Login.java
│ │ │ ├── Register.java
│ │ │ └── Search.java
│ │ ├── resources/ <-- Resource files (e.g., configuration files)
│ │ └── webapp/
│ │ ├── META-INF/ <-- Metadata files
│ │ ├── WEB-INF/
│ │ │ └── web.xml <-- Deployment descriptor
│ │ ├── pages/ <-- JSP pages for the web application
│ │ │ ├── books.jsp
│ │ │ ├── error.jsp
│ │ │ ├── login.jsp
│ │ │ ├── register.jsp
│ │ │ ├── search.jsp
│ │ │ └── success.jsp
│ │ ├── index.jsp <-- Landing page for the application
│ │ ├── styles/ <-- CSS files
│ │ └── web-resources/ <-- Additional web resources (if any)
│ ├── test/
│ │ ├── java/ <-- Unit tests for your application
│ │ └── resources/ <-- Test resources (e.g., test configuration)
├── target/ <-- Compiled classes and build artifacts (generated)
├── build/ <-- Build-related files (e.g., compiled WAR files)
└── sql/ <-- SQL scripts (if any)
The project uses appache maven for dependency management and forbuild and deploy. You need to install Maven in your computer. These are the instructions to deploy maven in your computer
Install Homebrew (if not already installed): Open Terminal and run the following command to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Maven using Homebrew
brew install maven
Verify the Installation: After installation, confirm that Maven is correctly installed by checking its version:
mvn -version
You should see output displaying the Maven version, Java version, and OS information.
- Download Maven from here
- Extract the downloaded zip file to a directory of your choice, e.g., C:\Program Files\Apache\Maven.
- Set Environment Variables:
- Open the Start menu, search for “Environment Variables,” and select “Edit the system environment variables.”
- In the System Properties window, click on “Environment Variables.”
- Under “System variables,” click “New” and add:
- Variable name: MAVEN_HOME
- Variable value: C:\Program Files\Apache\Maven (or your chosen directory)
- Find the Path variable in the “System variables” section, select it, and click “Edit.”
- Click “New” and add:
%MAVEN_HOME%\bin
5. Click “OK” to close all dialogs.
- Verify Installation:
mvn -version
You should see output displaying the Maven version, Java version, and OS information.
The Maven configuration file where dependencies, plugins, and project details are defined.
This is where your Java source code resides.
- auth/: Contains classes related to authentication and authorization (e.g.,
UserContext, annotations for access control). - bizlogic/: (Currently empty) A placeholder for business logic-related classes.
- dao/: Contains Data Access Objects that interact with the database.
- models/: Contains classes representing data entities.
- servlet/: Contains servlets that handle HTTP requests.
This directory is typically used for configuration files (like .properties files).
- META-INF/: Contains metadata files (usually related to the application server).
- WEB-INF/: Contains the
web.xmldeployment descriptor and other server-side configurations. - pages/: Contains JSP files used to render views in your web application.
- styles/: Contains CSS files for styling the web pages.
- index.jsp: The main entry point for your application.
Contains unit tests for your application.
The directory where compiled classes, JAR/WAR files, and other build artifacts are generated.
- build/: Directory for build-related files (optional).
- sql/: Directory for SQL scripts used to set up the database (optional).
To compile and package your project, run the following command in the terminal:
mvn clean packageThis command will:
- Clean any previous build artifacts.
- Compile the Java source code.
- Generate the
.warfile in thetarget/directory.
- Locate the generated
.warfile in thetarget/directory (e.g.,bookup.war). - Copy the
.warfile to thewebapps/folder of your Tomcat installation. - Start the Tomcat server:
/opt/homebrew/opt/tomcat/bin/catalina.sh start
- Access the application in your browser at:
http://localhost:8080/bookup
If you’ve configured the Tomcat Maven plugin in your pom.xml, you can deploy directly from the terminal.
To deploy the application:
mvn tomcat9:deployTo stop the deployed application:
mvn tomcat9:undeployOnce deployed, access your application in a web browser at:
http://localhost:8080/bookup
To run your unit tests, use the following command:
mvn testThis will:
- Compile the test classes located in
src/test/java. - Execute the tests using JUnit and Mockito.
- Generate a test report in the
target/surefire-reportsdirectory.
If you encounter issues with missing dependencies in Eclipse, try the following:
mvn clean install -UThen refresh your project in Eclipse:
- Right-click on your project > Maven > Update Project.
To force a clean build:
mvn clean
mvn packageIf you have SQL scripts in the sql/ directory, you can run them manually in your MySQL database to set up the schema:
mysql -u root -p < sql/bookup_user.sql- Compile the project:
mvn clean package - Deploy to Tomcat: Copy the
.warfile or usemvn tomcat9:deploy - Run tests:
mvn test - Clean project:
mvn clean install -U