我无法在 JBoss 7.1.1 中使用 tess4j OCR 库。我没有 Maven 配置,也不知道异常情况。我认为是与 slf4j 日志库的冲突问题。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String filein = getServletContext().getRealPath("/test/img/pic.png");
File imageFile = new File(filein);
ITesseract instance = new Tesseract();
try{
String result = instance.doOCR(imageFile);
System.out.println(result);
}catch (TesseractException e){
System.err.println(e.getMessage());
}
}
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].(...)facade.reports.OCRtest]] (http--0.0.0.0-8080-1) Servlet.service() para servlet (...)facade.reports.OCRtest lanzó excepción: java.lang.NoSuchMethodError: org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger()V
at net.sourceforge.tess4j.util.LoggerConfig.loadConfig(Unknown Source) [tess4j-3.3.0.jar:]
at net.sourceforge.tess4j.util.LoggHelper.toString(Unknown Source) [tess4j-3.3.0.jar:]
at net.sourceforge.tess4j.Tesseract.<clinit>(Unknown Source) [tess4j-3.3.0.jar:]
at (...)facade.reports.OCRtest.doGet(OCRtest.java:36) [classes:]
最佳答案
我在使用 tess4j 实现 OCR 时遇到过同样的问题。我做了很多研究来解决我的问题,通过 slf4j 遗留实现和重新配置我的 Maven 项目中使用的 log4j 属性来解决我的问题。
有一天,我在他们的官方页面中读到了有关删除导致问题的行的信息,即 removeHandlersForRootLogger();
,然后我确实从 loadderConfig.java
util 文件和 Eureka!! 中删除了这一行!它开始工作了。
请按照以下步骤操作:
从 offical site 下载整个项目.
找到
tess4j\util
文件夹。我的是这样的:D:\Tess4J\src\net\sourceforge\tess4j\util
。然后打开loaderConfig.java
文件并删除/注释removeHandlersForRootLogger();
行。稍后使用 Ant 命令再次构建整个项目。由于它是一个 Apache Ant 项目,请查看
build.xml
并探索如何构建 Ant 项目,学习新东西很有趣。
如果您没有幸运地构建项目,请在包含 build.xml 的相应文件夹中打开 cmd 提示符,然后输入 ant 并按 Enter 键,它将开始使用 build.xml feed 中的配置进行构建
瞧,您已经在
dist
文件夹中创建了自己的 JAR。现在将此 JAR 包含到您的项目存储库中。
关于java - tess4j OCRtest JBoss 错误 java.lang.NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42643767/