Program 2: Working with Maven: Creating a Maven Project, Understanding the
POM File, Dependency Management and Plugins.
Install Eclipse and Maven
• Ensure Eclipse IDE is installed. You can download it from the official website if
not already installed.
• Ensure Maven is installed on your machine. You can verify its installation by
running mvn -v in the command line.
Open Eclipse and Configure Maven
• Open Eclipse and go to Window > Preferences.
• Navigate to Maven and ensure it's configured correctly, pointing to your Maven
installation.
Create a New Maven Project
• In Eclipse, go to File > New > Other... and select Maven Project.
• Leave the default workspace location and click Next.
• Choose Create a simple project (skip archetype selection) and click Next.
Specify Project Details
• Enter the Group ID (usually your organization or package name).
• Enter the Artifact ID (the name of your project).
• Fill in the Version and Packaging (e.g., jar).
• Click Finish to create the project.
Understand the POM File
• The newly created project will have a pom.xml file in its root directory. This file
is crucial for Maven configuration.
• This XML file includes project configuration details, dependencies, and plugins.
Adding Dependencies
• Open pom.xml.
• To add a dependency, find the dependency information on Maven Repository
(e.g., https://mvnrepository.com/).
Add the dependency snippet within the <dependencies> tag. For example:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.3.RELEASE</version>
</dependency>
Adding Plugins
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Build the Project
• Right-click on the project in Eclipse's Project Explorer.
• Select Run As > Maven build....
• In the Goals field, type clean install to clean and install your project.
• Click Run to build the project with Maven, which will download necessary
dependencies and compile the project.