0% found this document useful (0 votes)
4 views6 pages

Devops Lab p5

This document outlines the steps to create a Maven project, including prerequisites such as installing Java JDK and Maven. It provides detailed instructions for setting up environment variables, creating a project, adding dependencies in the POM file, building the project, and running the JAR file. The guide emphasizes using specific commands in the command prompt to accomplish each task.

Uploaded by

rharshit337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Devops Lab p5

This document outlines the steps to create a Maven project, including prerequisites such as installing Java JDK and Maven. It provides detailed instructions for setting up environment variables, creating a project, adding dependencies in the POM file, building the project, and running the JAR file. The guide emphasizes using specific commands in the command prompt to accomplish each task.

Uploaded by

rharshit337
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB PROGRAM - 5

Create a Maven Project, Understanding the POM File, Dependency Management and
Plugins.

1. Prerequisites required
● Java JDK (version 21 preferable) must be installed.

● Confirm Java installation by typing the below command in command prompt:

java -version

Step 1: Download and install Maven from: https://maven.apache.org/download.cgi

● Install Binary Zip file only.

->apache-maven-3.9.6-bin.zip

❌ Do NOT Download:

● src.zip – contains source code (not needed for installation)

● .tar.gz – intended for Linux/Unix systems


Step 2 : Add Maven to your system path:

● MAVEN_HOME ➝ Path to Maven folder

● Add MAVEN_HOME/bin to the PATH

After Downloading:
1. Extract the zip file to a location like:

C:\Program Files\Apache\Maven\apache-maven-3.9.6

2. Set environment variables using setx (as explained below)


3. Open Command Prompt (Run as Administrator) and execute the following :

> setx MAVEN_HOME "C:\Program Files\Apache\Maven\apache-maven-3.9.6" /M

> setx PATH "%PATH%;C:\Program Files\Apache\Maven\apache-maven-3.9.6\bin" /M

4. Restart your Command Prompt and check:

-> Check whether is Maven is properly installed

5. Open Command Prompt and execute the following :


> mvn -v
Step 3: Create a Maven Project
-> Type the following in the cmd prompt

> mvn archetype:generate -DgroupId=com.example -DartifactId=demo-project -


DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

OR

-> After the Execution the above cmd on the command prompt, the project structure looks like
below.

1.
Step 4: Add a Dependency
-> Step 4 : Go to the demo-project folder and understand the usage of pom.xml file.

-> To use a library, add its dependency in the <dependencies> block,

Example: Add Gson (for JSON parsing):

-> Add the below dependency code section to the pom.xml file.

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

-> In the same way you can add any number of dependencies required for your application.
Step 5: Building Maven Project

-> Change the directory to demo-project :

> cd demo-project

> mvn compile

> mvn test

> mvn package


Step 6: Run the JAR File

-> If you have a main() method in App.java, run the JAR like this:

java -cp target/demo-project-1.0-SNAPSHOT.jar com.example.App

Note : The above steps is to run a Java Application using Maven.

You might also like