Tess4j in glassfish ERROR:java.lang.NoSuchFieldError: RESOURCE_PREFIX

萝らか妹 提交于 2019-12-13 00:34:30

问题


I'm using Tess4j 2.0.0 in oracle-glassfish3.1.1, Exception is:

java.lang.NoSuchFieldError: RESOURCE_PREFIX at net.sourceforge.tess4j.util.LoadLibs.(LoadLibs.java:60) at net.sourceforge.tess4j.TessAPI.(TessAPI.java:40) at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:256) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:237) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:221) at cn.uxcard.util.CaptchaUtil.getCaptcha(CaptchaUtil.java:29) at cn.uxcard.util.HttpConnection.getCaptcha(HttpConnection.java:60) at cn.uxcard.util.HttpConnection.tryCaptcha(HttpConnection.java:78) at cn.uxcard.util.HttpConnection.login(HttpConnection.java:90) at cn.uxcard.util.HttpConnection.tryLogin(HttpConnection.java:121) at cn.uxcard.util.HttpConnection.init(HttpConnection.java:148) at cn.uxcard.util.HttpUtil.getConnection(HttpUtil.java:28) at cn.uxcard.executor.FetchTodayConsumeRecordExecutor.run(FetchTodayConsumeRecordExecutor.java:29) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) at java.lang.Thread.run(Thread.java:662)

the glassfish load com.sun.jna.Platform class, don't use WEB-INF/lib/jna-4.1.0.jar but use "bundle://185.0:1/com/sun/jna/Platform.class". Can I change the glassfish classload order and if so how?


回答1:


I encountered the same issue while trying to develop a web application with Tess4j and after some research found out that class loaders in the GlassFish Server runtime follow a delegation hierarchy as specified in this link >>

https://docs.oracle.com/cd/E19798-01/821-1752/6nmndgmhp/index.html

Accordingly, placing the jar files (tess4j.jar, jna.jar, jai_imageio.jar, commons-io-2.4.jar) in the system extensions directory (domain-dir/lib/ext) resolved this error for me.

Versions Used:

• GlassFish Server 3.1.2.2 • jdk-7u80-windows-i586.exe • NetBeans IDE 8.0




回答2:


I experienced the same issue, I switch the JRE version to my eclipse Execution environment Java-SE-1.7(jre7) and solved the problem.




回答3:


The dependency on JNA RESOURCE_PREFIX string constant has been removed in the latest releases 3.4.9 (for Tesseract 3.05.01) and 4.0.2 (for Tesseract 4.0.0-beta.1). The library can now be used with Glassfish.



来源:https://stackoverflow.com/questions/31236060/tess4j-in-glassfish-errorjava-lang-nosuchfielderror-resource-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!