I am new to Maven and trying to compile a simple program using Log4j. When i compile the project using mvn compile then it brings downloads all the jar. I have already added the dependencies into pom.xml but not sure why it is not recognizing the slf4j.jar. Here is the program and snippet of pom.xml
package org.first.FirstMaven;
import org.slf4j.*;
public class App
{
public static void main( String[] args )
{
Logger logger = LoggerFactory.getlogger(App.class);
logger.info("Hello World!");
}
}
Pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
Error:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project MavenTestApp: Compilation failure /home/first/MAVEN/MavenTestApp/src/main/java/org/first/FirstMaven/App.java:[13,40] cannot find symbol symbol: method getlogger(java.lang.Class) location: class org.slf4j.LoggerFactory
You are using getlogger (small L), its getLogger .
public static void main( String[] args )
{
Logger logger = LoggerFactory.getLogger(App.class);
logger.info("Hello World!");
}
If you are using any IDE, try to use auto-complete feature ( for Eclipse Ctrl + Space ), to avoid such mistakes.
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.