Friday, April 5, 2024

Create Sample Java Web Application using Maven and Deploy it on Tomcat Server

Install Maven on windows:

https://phoenixnap.com/kb/install-maven-windows

Install maven on Linux:

Install Maven (Latest From Maven Repo)

Follow the steps given below to install the latest maven package from the official maven repo.

Step 1: Go to Maven Downlaods and get the download link of the latest package.

wget wget https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz

Step 2: Untar the mvn package to the /opt folder.

sudo tar xvf apache-maven-3.9.0-bin.tar.gz -C /opt

Step 3: Create a symbolic link to the maven folder. This way, when you have a new version of maven, you just have to update the symbolic link and the path variables remain the same.

sudo ln -s /opt/apache-maven-3.9.0 /opt/maven


Add Maven Folder To System PATH


To access the mvn command systemwide, you need to either set the M2_HOME environment variable or add /opt/maven to the system PATH.

We will do both by adding them to the profile.d folder. So that every time the shell starts, it gets sourced and the mvn command will be available system-wide.

Step 1: Create a script file named maven.sh in the profile.d folder.

sudo vi /etc/profile.d/maven.sh
Step 2: Add the following to the script and save the file.

export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Step 3: Add execute permission to the maven.sh script.

sudo chmod +x /etc/profile.d/maven.sh
Step 4: Source the script for changes to take immediate effect.

source /etc/profile.d/maven.sh
Step 5: Verify maven installation

mvn -version

Maven Command To Create Java Web Application:

mvn archetype:generate  -DgroupId=com.companyname.automobile -DartifactId=trucks -DarchetypeArtifactId=maven-archetype-webapp  -DinteractiveMode=false

Maven Command to generate artifact:

First go the location where pom.xml file is placed... and execute below command

#mvn package

Deploy Sample Web application on tomcat server:

Copy  the artifact from target folder and deploy it on tomcat server(tomcat deployment directory is webapps)











No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117