How to add Maven in a Java pom file?

In a Java project, Maven dependencies can be added by including a pom.xml file.

Create a pom.xml file in the root directory of the project, then add the required dependencies to the file. For example, to add JUnit dependency, you can add the following content to the pom.xml file.

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  ...
</project>

In the above code snippet, the tag contains all the dependencies. Each tag defines a single dependency, with specifying the organization ID, specifying the Artifact ID, specifying the version, and specifying the dependency’s scope.

After saving the pom.xml file, Maven will automatically download the necessary dependencies and build the project based on the definitions in the file. You can build the project using Maven command line or Maven plugins in your IDE.

bannerAds