简体   繁体   中英

Adding library to Maven project

I have created simple Maven Java project in Eclipse.

在此处输入图片说明

In package src/main/java I have create simple tst class and planing to use log4j there:

import java.util.Scanner;
import org.apache.log4j.Logger;

public class tst {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("hello");
        Scanner scan=new Scanner(System.in);
    }
}

I have added log4j in dependencies:

在此处输入图片说明

I expect Maven will download log4j jar for my project. Instead of that I have error Missing artifact log4j:log4j:jar:1.2 .

How to fix this problem? Is it possible to know what versions are available in log4j project?

mvnrepository.com says that the project Apache Log4j was move to Log4j Core . So try to update the artifact with this one:

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

When you add a library with Maven, always check the correct version in mvnrepository.com

And if you still have the error, try to update maven dependencies. Right click on the project and select

Maven -> Update Project

Sometimes when you update project libraries with Maven, Eclipse isn't able to download it directly and you have to force the refresh of the dependencies.

The problem is simply that there is no log4j in version 1.2.

Try version 1.2.17.

Just follow the path you chose, but use 1.2.17 instead of 1.2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM