How do you add a dependency to a Maven project?
A) By adding a
<dependency> element in the pom.xml fileB) By adding a
<plugin> element in the pom.xml fileC) By creating a
dependency.xml fileD) By specifying it in the
project.xml fileAnswer:
A) By adding a
<dependency> element in the pom.xml fileExplanation:
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.