tess4j NoSuchFieldError:在Glassfish上使用Primefaces的RESOURCE_PREFIX,但不包含JUnit

时间:2017-06-07 11:51:56

标签: java maven primefaces tesseract tess4j

我正在尝试使用tess4j在PDF上进行OCR,当我使用JUnit测试来“读取”PDF时这是完美的工作,但是当我使用Primefaces FileUpload运行它时却没有。

侦听器调用与JUnit测试完全相同的OCR类,除了返回OCR结果的字符串。这是java类:

import java.io.File;

import net.sourceforge.tess4j.Tesseract;

public class PDFToText
{

    public String doOCR(){
            try
            {
                Tesseract tess = new Tesseract();
                String text = "";

                imagePath = new File("D:/path/to/my.pdf");


                tess.setDatapath("D:/path/to/my/tessdata");
                text = tess.doOCR(imagePath);
                System.out.println(text);

                return text;
            } catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
}

我在SO上阅读了所有这些解决方案,关于JNA版本与com.sun.jna 3.0.9等的冲突。

但是我正在使用的tess4j的永不版本(3.4.0)甚至不再包含com.sun.java 3.9.0,它使用net.java.dev 4.1.0基于上面的用法maven存储库以及jar中的源代码看起来它具有RESOURCE_PREFIX属性。

也做了@ S.Isurika在这里所说的,这没有帮助:Tess4j in glassfish ERROR:java.lang.NoSuchFieldError: RESOURCE_PREFIX ,无论如何,我不想在任何目录中放置一些罐子,因为我正在使用maven(maven for eclipse)。

我也在为我的项目使用Selenium,其maven配置依赖于net.java.dev.jna版本3.4.0,但这看起来不像是一个问题,因为它既不缺少Platform文件中的RESOURCE_PREFIX

首先它对我来说似乎是一个缓存问题,但在我清理了项目后,清理了maven,重建了maven的索引,删除了我的.m2文件夹,删除了GL上的部署,重新启动了eclipse甚至是机器,我迷路了

感谢您的帮助!

环境:

  • tess4j 3.4.0(使用net.java.dev.jna 4.1.0。)
  • jai-imageio-core 1.3.1
  • java 1.8
  • maven-compiler-plugin 2.3.2
  • maven-war-plugin 2.3
  • Glassfish 4.0
  • Primefaces 6
  • Windows 7
  • myEclipse 2017

这是我的堆栈跟踪:

Exception message:  
/templates/pages/secured/menu/page.xhtml @121,31 fileUploadListener="#{myBean.handleFiles}": java.lang.NoSuchFieldError: RESOURCE_PREFIX

Exception String:   
javax.faces.FacesException: 

/templates/pages/secured/menu/page.xhtml @121,31 fileUploadListener="#{myBean.handleAttachmentFiles}": java.lang.NoSuchFieldError: RESOURCE_PREFIX

Exception Cause:    
javax.el.ELException: /templates/pages/secured/menu/page.xhtml @121,31 fileUploadListener="#{mybean.handleAttachmentFiles}": java.lang.NoSuchFieldError: RESOURCE_PREFIX
Exception Class name:   

javax.faces.FacesException

Stack trace:    

javax.faces.FacesException: /templates/pages/secured/menu/page.xhtml @121,31 
fileUploadListener="#{mybean.handleAttachmentFiles}": java.lang.NoSuchFieldError: RESOURCE_PREFIX 
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:86) 
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) 
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) 
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) 
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) 
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) 
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AmeractIOStrategy.fireIOEvent(AmeractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AmeractThreadPool$Worker.doWork(AmeractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AmeractThreadPool$Worker.run(AmeractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745) Caused by: javax.el.ELException: /templates/pages/secured/menu/page.xhtml @121,31 fileUploadListener="#{mybean.handleAttachmentFiles}": java.lang.NoSuchFieldError: RESOURCE_PREFIX
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at org.primefaces.component.fileupload.FileUpload.broadcast(FileUpload.java:319)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:755)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) ... 30 more Caused by: java.lang.NoSuchFieldError: RESOURCE_PREFIX
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(LoadLibs.java:63)
at net.sourceforge.tess4j.util.PdfUtilities.<clinit>(PdfUtilities.java:214)
at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:392)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196)
at com.me.utils.file.OCR.PDFToText.doOCR(PDFToText.java:121)
at com.me.proj.webLayer.requestScoped.mybean.handleAttachmentFiles(mybean.java:380)
at com.me.proj.webLayer.requestScoped.mybean$Proxy$_$$_WeldClientProxy.handleAttachmentFiles(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.el.parser.AstValue.invoke(AstValue.java:275)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) ... 34 more

0 个答案:

没有答案