When I tried to read an excel file this error shows:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.logging.log4j.Logger.atDebug()Lorg/apache/logging/log4j/LogBuilder;
pointing to this line:
try (FileInputStream inputStream = new FileInputStream(configFile.getPath());
XSSFWorkbook workbook = new XSSFWorkbook(inputStream)) {
I tried to exclude the log4j dependency from the apache poi but it's now working:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
It seems apache poi version 5.2.2 uses or calls the log4j. Do I also need to included it to my dependency? or is there proper way to exclude log4j?
org.apache.logging.log4j.Logger
is part of org.apache.logging.log4j:log4j-api
. If you are excluding org.apache.logging.log4j:log4j-core
, it will also exclude org.apache.logging.log4j:log4j-api
You need to have log4j-api
in your classpath.
If you are using slf4j you can find the log4j-over-slf4j
More information on Apache POI's Logging Framework