How do you add a dependency to a Maven project?

How do you add a dependency to a Maven project?

A) By adding a <dependency> element in the pom.xml file
B) By adding a <plugin> element in the pom.xml file
C) By creating a dependency.xml file
D) By specifying it in the project.xml file

Answer:

A) By adding a <dependency> element in the pom.xml file

Explanation:

To add a dependency to a Maven project, you include a <dependency> element inside the <dependencies> section of the pom.xml file. This element specifies the group ID, artifact ID, and version of the dependency, which Maven will download and include in the project’s classpath.

For example:


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.5.4</version>
    </dependency>
</dependencies>

In this example, the Spring Boot Web Starter dependency is added to the project.

Reference links:

https://www.javaguides.net/p/maven.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top