How to create Maven dependencies?

Hello stackoverflow users. I created a maven project, but there is no place called "Maven Dependecies" in the project explorer. How can I solve this.

Project Explorer

The content of pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>01-com.maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>

Upvotes: 0

Views: 527

Answers (2)

zforgo
zforgo

Reputation: 3316

Because you don't have any dependency the Maven Dependencies section will be empty. Take a look the the official documentation and follow the instructions how to add a dependency with the desired scope e.g.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>01-com.maven</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.11</version>
            <!-- this is a compile scoped dependency so it available in production code and the tests and in runtime -->
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
            <!-- it will be only available during compiling and running test classes -->
        </dependency>
    </dependencies>
</project>

Upvotes: 2

Gonzalo Matheu
Gonzalo Matheu

Reputation: 10104

You might want to add the dependencies section to your pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>01-com.maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-b</artifactId>
      <version>1.0</version>
      <type>bar</type>
      <scope>runtime</scope>
    </dependency>
  </dependencies>

</project>

Excerpt from Maven's documentation

Upvotes: 0

Related Questions