wangguanquan / eec

A fast and lower memory excel write/read tool.一个非POI底层,支持流式处理的高效且超低内存的Excel读写工具
https://github.com/wangguanquan/eec/wiki
Apache License 2.0
198 stars 55 forks source link

编译通过了,但是执行总是" No SLF4J providers were found" #357

Closed lingbl closed 1 year ago

lingbl commented 1 year ago

编译 javac.exe test.java 没问题,但是执行java.exe test就是错: SLF4J: No SLF4J providers were found. SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

Exception in thread "main" java.lang.NoClassDefFoundError: org/ttzero/excel/util/ExtXMLWriter at org.ttzero.excel.reader.ExcelReader.read(ExcelReader.java:654) at org.ttzero.excel.reader.ExcelReader.read(ExcelReader.java:233) at org.ttzero.excel.reader.ExcelReader.read(ExcelReader.java:155) at test.testRead(test.java:17) at test.main(test.java:10) Caused by: java.lang.ClassNotFoundException: org.ttzero.excel.util.ExtXMLWriter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 5 more

//代码test.java:

import org.ttzero.excel.reader.*; import org.ttzero.excel.reader.XMLSheet; import java.nio.file.Paths; import java.io.IOException;

public class test { public static void main(String[] args) { testRead(); System.out.println("Hello World"); }

public static void testRead() { try {
ExcelReader reader = ExcelReader.read(Paths.get("test.xlsx")); } catch (IOException e) { e.printStackTrace(); } }

}

wangguanquan commented 1 year ago

EEC依赖dom4j和slf4j,命令行运行的时候Windows请指定 -cp .;./lib/slf4j-api-1.7.32.jar;./lib/dom4j-2.1.3.jar;./lib/eec-0.5.9.jar,linux请指定 -cp .:./lib/slf4j-api-1.7.32.jar:./lib/dom4j-2.1.3.jar:./lib/eec-0.5.9.jar

testReader方法内容替换

try (ExcelReader reader = ExcelReader.read(Paths.get("test.xlsx"))) {
    reader.sheet(0).rows().forEach(System.out::println);
} catch (IOException e) {
    e.printStackTrace();
}

terminal line

wangguanquan commented 1 year ago

另外No SLF4J providers were found这个异常没有关系,slf4j是日志门面层,日志采集层需要引入log4j或者logback,否则就会提示这个异常,它不影响程序正常执行只是无法输出日志

如果想要消除这个异常只需要将log4j或者logback添加进class path即可,以下是添加logback的命令 -cp .;./lib/slf4j-api-1.7.32.jar;./lib/dom4j-2.1.3.jar;./lib/logback-core-1.2.3.jar;./lib/logback-classic-1.2.3.jar;./lib/eec-0.5.9.jar

wangguanquan commented 1 year ago

相比使用javac和java命令行,使用jshell更方便所见即可得

jshell --class-path .:./lib/slf4j-api-1.7.32.jar:./lib/dom4j-2.1.3.jar:./lib/logback-classic-1.2.3.jar:./lib/logback-core-1.2.3.jar:./lib/eec-0.5.9.jar import org.ttzero.excel.reader.ExcelReader ExcelReader.read(Paths.get("./test.xlsx")).sheet(0).rows().forEach(System.out::println)

jshell line

lingbl commented 1 year ago

谢谢热心回答