我在我的 JSF Web 应用程序中使用 Tesseract。
当我熟悉 Tesseract API 作为一个简单的 java 项目时,它可以毫无问题地工作,然后一旦我将它集成到我使用 apache tomcat 7 服务器的 web 项目中,我就会得到以下异常:
20:27:56.291 [http-apr-8090-exec-14] WARN net.sourceforge.tess4j.util.LoadLibs - C:\apache-tomcat-7.0.68\temp\tess4j\win32-x86-64\gsdll64.dll (The process cannot access the file because it is being used by another process)
java.io.FileNotFoundException: C:\apache-tomcat-7.0.68\temp\tess4j\win32-x86-64\gsdll64.dll (The process cannot access the file because it is being used by another process)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1142)
at org.apache.commons.io.FileUtils.doCopyDirectory(FileUtils.java:1446)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1388)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1268)
at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:1237)
at net.sourceforge.tess4j.util.LoadLibs.copyResources(LoadLibs.java:136)
at net.sourceforge.tess4j.util.LoadLibs.extractTessResources(LoadLibs.java:105)
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(LoadLibs.java:59)
at net.sourceforge.tess4j.util.PdfUtilities.<clinit>(PdfUtilities.java:207)
at net.sourceforge.tess4j.util.ImageIOHelper.getIIOImageList(ImageIOHelper.java:314)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:214)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:198)
at Util.ReadFiles.OCR(ReadFiles.java:248)
at Util.ReadFiles.readImages(ReadFiles.java:184)
at Util.ReadFiles.dispatcher(ReadFiles.java:97)
at Util.ReadFiles.<init>(ReadFiles.java:71)
at Web.Controller.DocumentController.search(DocumentController.java:350)
at Web.Controller.DocumentController.getDocuments(DocumentController.java:780)
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:99)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:184)
at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:46)
at org.apache.el.parser.AstNot.getValue(AstNot.java:43)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1276)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1286)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at Util.AuthorizationFilter.doFilter(AuthorizationFilter.java:35)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这是我的调用方法:
/**
* Reading PDF and images with Tesseract OCR
* @param filePath
* @return content
*/
public String OCR(String filePath)
{
String content = null;
File imageFile = new File(filePath);
Tesseract ins = new Tesseract();
ins.setDatapath("../tessdata");
try {
content = ins.doOCR(imageFile); // <-- Exception thrown from here
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
return content;
}
正如您在此屏幕截图中看到的那样,存在 dll,并且我的 Web 应用程序是唯一使用 tesseract 的应用程序,所以我真的不知道哪个进程正在使用这些库......请有任何想法!