我的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提要中的配置进行构建


Voilà,您在dist文件夹中创建了自己的JAR。
现在,将此JAR包含到您的项目存储库中。

10-08 15:32