https://github.com/orende/jsp-tomcat-maven-example
An simple JSP app, WAR-packaged, Tomcat-deployed, Maven-built.
https://github.com/orende/jsp-tomcat-maven-example
Last synced: about 1 year ago
JSON representation
An simple JSP app, WAR-packaged, Tomcat-deployed, Maven-built.
- Host: GitHub
- URL: https://github.com/orende/jsp-tomcat-maven-example
- Owner: orende
- Created: 2023-12-27T13:15:58.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-02T11:23:57.000Z (over 2 years ago)
- Last Synced: 2025-01-04T16:39:45.709Z (over 1 year ago)
- Language: Java
- Size: 74.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example JSP project with Tomcat and Maven
A simple JSP project to introduce working with Maven.
The project is packaged as a war file and deployed onto a dockerized Tomcat server.
## Building
The below command removes the target folder, compiles the code, runs the tests and creates a WAR file.
`mvn clean install`
## Running locally
The below command compiles the code, runs the tests, creates a WAR file and deploys it onto an in-memory Jetty web server.
`mvn install jetty:run`
You can now access the app with a brower at http://localhost:8080. You can also send HTTP requests to the REST API at
http://localhost:8080/rest/hello.
### Deploying to Tomcat
To deploy the code onto a dockerized Tomcat server, use the following commands:
```shell
mvn clean install
docker run \
-it --rm \
-v $PWD/target/tomcatjspexample-1.0-SNAPSHOT.war:/usr/local/tomcat/webapps/ROOT.war \
-p 8080:8080 \
tomcat:9.0
```
### Using a Docker container for the database
To setup a dockerized MySQL db and initialize it with schemas, run the following:
```shell
# create a MySQL docker container with a root user and db
docker run \
--name some-mysql \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
-e MYSQL_DATABASE=testdb \
-p 3306:3306 \
-d mysql:8.0
# test the connection to the db
mysql -h localhost -P 3306 --protocol=tcp -u root -p
# run a flyway migration
flyway \
-user=root \
-password=my-secret-pw \
-url=jdbc:mysql://localhost:3306/testdb \
-locations=filesystem:/$PWD/src/main/resources/db/migration \
migrate
```