raptor496
raptor496

Reputation: 267

log4j package does not exist

I'm running mvn install, getting below error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile 

error: package org.apache.log4j does not exist

In my project hierarchy I have log4j-1.2.15.jar added as a Referenced Libraries..not sure what I'm missing.

Part of POM file with log4j dependency (should I change the version to just say 1.2...or possible remove the scope below?):

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>1.2.15</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>1.2.15</version>
    </dependency>

Upvotes: 10

Views: 55621

Answers (3)

Christopher Hoffman
Christopher Hoffman

Reputation: 192

For eclipse users this directly resolved this problem. There is no need to re-install anything with maven installed in eclipse oxygen centos 6. Vogella tutorial below says to resolve the dependency by adding the .jar via downloaded index at startup. As identified above answer 1.2.17 is around the same solution that worked for me (1.2.15) You must launch eclipse in a terminal with JAVA_HOME set as mentioned above. Eclipse will handle the rest.

How to use maven in eclipse

Identifies how to download the dependency list. Once you setup your project you open the pom gui and select Dependencies. You search for the above mentioned library select and add it. During initial build, the dependent .jar is downloaded and configured dynamically via the pom.xml state injection, this is why no manual deleting or re-install is necessary.

It is still not managed- To manage the dependency, i.e. add it to the pom, you select the item you just added and click manage and follow the prompts to add it the Dependency Management list. This is an automatic pom addition from the gui - `

    <dependency>
        <groupId>org.eclipse.ecf</groupId>
        <artifactId>org.apache.log4j</artifactId>
        <version>1.2.15.v201012070815</version>
    </dependency>`  

When the Dependency Management list is populated your library will display a (managed:version) tag in orange.

Start smiling, right click pom, run as maven build, the errors should be gone.

Upvotes: 0

Liz Lamperouge
Liz Lamperouge

Reputation: 681

For log4j I only use this libraries:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

Upvotes: 4

Vasyl Lyashkevych
Vasyl Lyashkevych

Reputation: 2222

At first, it can be related with some your customizations of the environment or with dependencies in your *.pom file (Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin (default-compile) on project: Fatal error compiling: tools.jar not found). You need to check default installed "jre" to a jdk. Also ensure maven instalation and , namely paths: $JAVA_HOME and $M2_HOME

for example the paths adjustments when you have linux: enter image description here

When I execute the command: echo $JAVA_HOME I will have /usr/lib/jvm/java-9-oracle and appropriate path for maven

Upvotes: 0

Related Questions