0

I started a new maven-project with maven-archetype-quickstart. I use Eclipse Java EE IDE for Web Developers in Version: Oxygen.3a Release (4.7.3a), Build id: 20180405-1200 on Ubuntu 17.10.

My POM.XML is

 <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>org.rogatio</groupId>
  <artifactId>helloworld</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>helloworld</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.11.0</version>
    </dependency>
    <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
       <version>2.11.0</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-surefire-plugin</artifactId>
           <version>2.17</version>
           <configuration>
        <systemProperties>
          <property>
            <name>log4j.configurationFile</name>
            <value>log4j2.properties</value>
          </property>
        </systemProperties>
      </configuration>
    </plugin>
  </plugins>

Main-Class is package org.rogatio.helloworld;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class App {
final static Logger logger = LogManager.getLogger(App.class);

public static void main(String[] args) {

    logger.info("App started.");

    System.out.println("Hello World!");

    sayHi();

}

public static String sayHi() {
    logger.info("Hi!");
    System.out.println("Hi!");
    return "Hi!";
}
}

My Project-Structure is

Filestructure

The Test-Class is

package org.rogatio.helloworld;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class AppTest 
extends TestCase
{
/**
 * Create the test case
 *
 * @param testName name of the test case
 */
public AppTest( String testName )
{
    super( testName );
}

/**
 * @return the suite of tests being tested
 */
public static Test suite()
{
    return new TestSuite( AppTest.class );
}

public void testApp()
{
    assertTrue( true );
}

public void testHi()
{
    assertEquals( App.sayHi(), "Hi!" );
}
}

The problem is that running Maven-Test throws

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.rogatio.helloworld.AppTest
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Hi!
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.233 sec - in org.rogatio.helloworld.AppTest

Also running the App throws

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Hello World!
Hi!

I didn't get whats wrong. Everything is set and resources are in classpath. Any idea whats wrong? Is my POM wrong?

You can find the complete project under https://ufile.io/8zy0a

Matthias Wegner
  • 303
  • 4
  • 18
  • Try enabling log4j2 debugging. You can do so by adding `status = trace` in log4j2 configuration file or run application with `-Dlog4j2.debug=true` VM arguments. – Vikas Sachdeva May 17 '18 at 07:53
  • Perhaps maven wasn't able to download the log4j2-core jar for some reason, try checking whether the jar actually exists in your local maven repository directory. I don't see anything wrong with the way the project is configured and am able to successfully run maven:test but I'm using Eclipse Java EE IDE for Web Developers. Version: Mars.2 Release (4.5.2) Build id: 20160218-0600 on Windows 10 so I'm not exactly duplicating your environment. – D.B. May 20 '18 at 01:20
  • Sorry, both of your tips are not working. Library is in classpath and debug shows the ERROR above. So no change at all. – Matthias Wegner Jun 21 '18 at 17:44
  • I found a tip at https://stackoverflow.com/questions/39560740/log4j2-could-not-find-a-logging-implementation-with-sprint-boot. I deleted all from maven-repo in folder log4j. Then i called maven update and everything works. So i had a problem in the maven repo, not eclipse. – Matthias Wegner Jun 21 '18 at 19:48

0 Answers0