Goal: The purpose of this project is to test java application connectivity with AWS RDS(MySQL)
Database Name : jwt
src/main/webapp/login.jsp
src/main/webapp/userRegistration.jsp
CREATE TABLE
USER(
idint(10) unsigned NOT NULL auto_increment,
first_namevarchar(45) NOT NULL,
last_namevarchar(45) NOT NULL,
emailvarchar(45) NOT NULL,
usernamevarchar(45) NOT NULL,
passwordvarchar(45) NOT NULL,
regdate date NOT NULL, PRIMARY KEY (
id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Be in the project directory
mvn package
Copy the artifact i.e war file from target directory to Application Server Webapps directory
- Apache Tomcat is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. Tomcat provides a "pure Java" HTTP web server environment in which Java code can run. By default, Apache Tomcat runs on port 8080.
- Like we installed Apache Web Server to deploy the website, we need to install Apache Tomcat to go with dynamic applications.
- Tomcat requires Java to function.
java
sudo yum -y install java-1.8*
wget https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.94/bin/apache-tomcat-7.0.94.tar.gz
tar xvf apache-tomcat-7.0.94.tar.gz
# Tomcat runs on port 8080
sudo netstat -ntpl | grep 8080
~/apache-tomcat-7.0.94/bin/startup.sh
# Hit enter
sudo netstat -ntpl | grep 8080
- Browse by public-ip:8080, you will be able to see the Tomcat page.
- Apply a custom TCP rule with port 8080 from anywhere in security group, as Tomcat works on port 8080 by default.
Fetch application code
# Install Git
sudo yum -y install git
# Fetch code
git clone -b aws https://github.com/DL-Murali/car-insurance-app.git
- According to this application, we need a database “jwt” and table called “USER”. Browse: http://App-Server-Public-IP:8080/LoginWebApp.
mysql
sudo yum -y install mysql
mysql -h <rds-end-point> -u root -p
# login to database server and create
Database - jwt
create database jwt;
# create table USER
show databases;
use jwt;
show tables;
CREATE TABLE `USER` (
`id` int(10) unsigned NOT NULL auto_increment,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`email` varchar(45) NOT NULL,
`username` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
`regdate` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
show tables;
select * from USER;
cd aws-rds-java
vi src/main/webapp/userRegistration.jsp
vi src/main/webapp/login.jsp
# Change database address
- Building - Conversion of source code to binary code. In order to build, we need a build tool, which is “MAVEN”.
mvn
sudo yum -y install maven
cd ~/aws-rds-java
ls target
mvn package
ls target
- Copy the war file generated in target directory to Apache Tomcat webapps directory.
cp /home/ec2-user/aws-rds-java/target/LoginWebApp.war /home/ec2-user/apache-tomcat-7.0.94/webapps