I moved a functionality of my Maven project because instead of a file.war, I wanted a .jar file to be able to run it from the command line. The problem is when I have been copying the dependencies of this project to the new one, my pom is the next one:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MY_GROUP_ID</groupId>
<version>1.0.0.0</version>
<artifactId>MY_ARTIFACT_ID</artifactId>
<description>MY_DESCRIPTION</description>
<name>MY_NAME</name>
<packaging>jar</packaging>

<properties>
    <log4j.version>2.11.1</log4j.version>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongo-java-driver</artifactId>
        <version>3.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.3.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.55</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.4</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.5</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>27.0.1-jre</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${log4j.version}</version>
    </dependency>


</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

The main problem that I get is that the methods log.error () and log.info () that I had written in code in the other application and that worked perfectly, in this new project do not work, when adding the @ Slf4j tag to my class, Example:

  @Slf4j
  @Data
  public class MY_CLASS {
  private String variable1;
  private String variable2;
  private String variable3;
  private String variable4;
  private String variable5;

The error that I get it's next one:

Logger cannot be resolved to a type.

org.slf4j cannot be resolved to a type.

org.slf4j.LoggerFactory cannot be resolved to a type.

I clean project, i reinstall project lombok, etc...

Thank's for help ^^

2

There are 2 best solutions below

0
On

I had this problem, and I had to add the missing dependency:

<dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-api</artifactId>
</dependency>
1
On

For what I know, in eclipse if you have "cleaned and compiled" it with maven and the dependencies didn't load properly try right clicking and go to maven, then "Update Project", in the new window you should select everything related to that project and mark "Force update of Snapshot/Releases", this could maybe solve your problem.