I’m new to Maven. I’m trying to build a test project, which includes log4j.
My java class is just a ‘hello world’ with an import for log4j like this:
import org.apache.log4j.Logger;
My pom.xml includes the following section:
<build>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
</dependencies>
</dependencyManagement>
...
</build>
I haven’t downloaded log4j jars at this point …..
I run:
mvn install.
I get:
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
App.java:[2,23] package org.apache.log4j does not exist
...
So I am obviously misunderstanding how Maven works here….
I thought I should be able to ship (as a minimum) a ‘pom.xml’ and my code to another user, and Maven should fetch the deps ?
Welcome to the Maven world 😉
You have to remove the
<dependencyManagement>tags, it should work.This tag is used when you use Maven modules (see the Maven doc)