Why is tessdata throwing Exceptions? - tesseract

All is happening on MAC in SpringBoot WAR file deployed in Tomcat:
I have tesseract 4.1.0 installed (via brew on Mac).
For Tessdata - OCR on Mac
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>4.4.0</version>
</dependency>
I also updated SpringBoot today to:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Now, when I try to run the OCR logic in tessdata (Service method in SpringBoot), I am first getting this error (on the mac):
java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;)Lcom/sun/jna/Library;
Then, if I try to OCR the Spanish png file again, I get this result:
"Could not initialize class net.sourceforge.tess4j.TessAPI"
The Tessdata code where the crash occurs seems to be:
public String doOCR(BufferedImage var1) throws TesseractException {
return this.doOCR((BufferedImage)var1, (Rectangle)null);
I've seen postings here about this problem, but all the ones I've seen are for Windows. I also tried to load the dependency for jna just in case, but that made no difference.
Has anyone faced and fixed this issue?
The problem appears to be with the tess4j 4.4.0. If I back it out to the last version, then things work again.
Would really appreciate some ideas.

It seems your application is loading an old JNA version. com.sun.jna.Native.load is new in JNA 5.x.x. So make sure you use the latest JNA version.
https://groups.google.com/forum/#!topic/jna-users/VKbCGUcotkg

Related

Optaplanner - drools file cannot be compiled when project is deployed

We developped a SpringBoot project with Java 11 using optaplanner-core and defining rules in a Drools file. We have no issue for running the app in intelliJ with JDK.
We then deployed the app onto Azure app service where a JRE is installed. We get the following error:
Caused by: org.kie.memorycompiler.KieMemoryCompilerException:
Cannot find the System's Java compiler. Please use JDK instead of JRE or add drools-ecj dependency to use in memory Eclipse compiler
We tried to add the following dependencies but we still get the same error:
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-core</artifactId>
<version>8.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-ecj</artifactId>
<version>7.51.0.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.26.0</version>
</dependency>
Would anyone know how to solve this problem ?
Thank you
Adding drools-ecj won't really fix this. The error message is misleading.
Using a JDK instead of a JRE. The easiest way is to upgrade to Java 11 (or higher), as that only comes with a JDK.
If running optaplanner with a JDK is no option for you, you can change the solver config to
<solver>
<scoreDirectorFactory>
<droolsAlphaNetworkCompilationEnabled>false</droolsAlphaNetworkCompilationEnabled>
</scoreDirectorFactory>
</solver>
and if you're using unit tests for java constraints that use the ConstraintVerifier, instantiate it like this
new DefaultConstraintVerifier<>(new MyConstraints(), SolutionDescriptor.buildSolutionDescriptor(myModelClasses))
.withDroolsAlphaNetworkCompilationEnabled(false)
However: From what I understood, disabling the drools alpha network compiler usually comes with a performance impact.

can not find osgi.enroute.iot.pi.provider dependency

I am trying to do this tutorial
http://enroute.osgi.org/tutorial_iot/120-exploring.html
but I have got a problem with:
osgi.enroute.iot.pi.provider
package is not find so I can resolve bndrun dependencies:
Unable to resolve <<INITIAL>> version=null:
missing requirement osgi.enroute.iot.pi.provider
and when I try with
osgi.enroute.iot.pi.command
dependencies not found:
Unable to resolve <<INITIAL>> version=null:
missing requirement enroute.iot.raspberry.application
-> Unable to resolve enroute.iot.raspberry.application version=1.0.0.201611270001:
missing requirement com.pi4j.system]
I manually dowload and add pi4j in my project build path so I haven't no more eclipse problem but I fell that it is not a good solution for osgi and it not run on my remote raspberry ssh console...
Thanks to Daghan from the osgi mailing list who provide a solution:
"osgi.enroute.iot.pi.provider" is no longer a part of enroute distro. Please remove the manually downloaded pi4j from your project and do the following:
1- open cnf>central.xml
2- Add the following
<!-- https://mvnrepository.com/artifact/org.osgi/osgi.enroute.iot.pi.provider -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.enroute.iot.pi.provider</artifactId>
<version>2.0.0</version>
</dependency>
This solve my problem but the include pi4j dependency isn't up to date for raspberry so I prefer add
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>1.1</version>
</dependency>
and everything works like a charm now!

Maven - Suppress Overriding managed version warning in Eclipse

I am using spring-boot, and experienced an error similar to the one described here. I added the following to my pom.xml.
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId><!--$NO-MVN-MAN-VER$-->
<version>1.1.0.Final</version>
</dependency>
I am overriding the validation-api 1.0.0 dependency defined in my parent pom.xml, by way of Spring boot, and this gives the pesky warning message:
Overriding managed version 1.0.0.GA for validation-api
How can I permanently suppress this warning message in Eclipse? It shows up both in my pom.xml and my problems view.
When that warning shows up, you can open the Quick-Fix menu on the warning (Ctrl+1) and select
Ignore this warning
This will add the comment on the version line, like :
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>
Your problem is you manually added that comment on the wrong line.
Since the project is using spring-boot, a more proper answer could be found here: https://stackoverflow.com/a/35385268/1568658
(And since I got the same issue, and the above answer also is not very complete. I would add an answer here.)
Reason of issue:
spring-boot has defined many dependencies & their versions, when you use spring-boot as parent, these dependencies got inherited, and overriding one of the dependency with a different version would get the warning, because it might break other libraries' dependencies.
Solution:
Define a property for that dependency between <properties></properties>, to specify the version.
e.g
<properties>
<reactor.version>2.5.0.BUILD-SNAPSHOT</reactor.version>
</properties>
How to find the property name:
Open your pom.xml in IDEA or Eclipse.
Ctrl + Click on the <parent> tag to open pom of parent, and need to click twice recursively to finally get to the pom file with artifactId as spring-boot-dependencies.
Once you have opened that pom, search for your dependency, e.g servlet-api, and you can see the default version.
There is a document from spring explains it better: https://spring.io/blog/2016/04/13/overriding-dependency-versions-with-spring-boot
Enter version that you need in main pom.
This warning means that you are trying to override artifact version that is defined in your main (top level) pom. Just enter version that you need in main pom and you don't even need to use <version /> in other poms for this dependency.
My issue is with lombok.jar version. I do have multiple lombok versions and eclipse somehow taking a version but it detected more versions so unable to pick it's version. So I went to maven folder (.m2) and deleted the extra versions of lombok, did maven update on project, error gone.
But I haven't provided lombok version anywhere, eclipse choose a version, don't know how.
useful ! I resolve the problem. As the module pom file declare 9.2.12.M0 while the spring-boot refer to the V9.3 . I overwrite the V9.2 in the parent pom file. follow by "Eric Wang"

SOAP web services NPE on redeployment Tomcat 6

I'm using Tomcat 6 and I have a web application that uses a SOAP web service. I generated the client classes to use using cxf-codegen-plugin in maven, my dependencies are :
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.6.1</version>
</dependency>
Everything works until I redeploy my war on tomcat (or even doing a simple touch on it: no code modification at all). Using the same url to access my page that makes the SOAP service call I have this weird NPE:
java.lang.NullPointerException
at com.ctc.wstx.util.SymbolTable.findSymbol(SymbolTable.java:385)
at com.ctc.wstx.sr.StreamScanner.parseLocalName(StreamScanner.java:1831)
at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:2997)
at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2941)
at com.ctc.wstx.sr.BasicStreamReader.handleRootElem(BasicStreamReader.java:2078)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2058)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1117)
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:81)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:78)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:99)
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:89)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.hasWSDLDefinitions(RuntimeWSDLParser.java:209)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:119)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56)
at some.package.flightinfo.model.flightstatsv2.soap.AirportsV1SoapService.<init>(AirportsV1SoapService.java:48)
at some.package.flightinfo.adapter.FlightStatsV2ContentAdapter.getAirportsByGPSCoordinate(FlightStatsV2ContentAdapter.java:107)
The only way I can get my web application working again is to restart tomcat which is no option at all.
I am totally clueless on what's going on, has anyone ever experienced this problem before?
Cheers.
Well, you are missing the cxf-rt-frontend-jaxws dependency. Thus, you are ending up using the JAX-WS reference impl built into the JDK, not CXF. If you add the CXF dependencies, does that fix it? Could be a bug in the RI or something.

ClassNotFoundException when I try to deploy to Tomcat / tc Server in Eclipse / STS

I'm new to Eclipse/STS, and I am having deploying to Tomcat / tcServer. My project builds just fine and deploys to Tomcat fine both in Netbeans and directly to Tomcat, but it will not deploy to Tomcat or tc Server in Eclipse. I get a ClassNotFoundException for org.hibernate.HibernateException, which I know is on the included in the pom.
Here's my log output if it helps.
Also in the markers view, I see the following build path problem:
Archive for required library: '~/.m2/repository/org/hibernate/hibernate-core/4.1.1.Final/hibernate-core-4.1.1.Final.pom' in project 'flamespass-web-dev' cannot be read or is not a valid ZIP file
I found a work around:
I noticed that I had hibernate-core:4.1.1.Final in my Dependency Hierarchy twice, so I tried a few things, and specifying the newest version of hibernate-core in my dependencyManagement node fixed my problem.
I am not sure why. I can only assume that the two copies of hibernate-core:4.1.1 were creating some sort of ambiguity that m2eclipse or WTP couldn't understand even though my external Maven/Tomcat could. I would really appreciate any explanation or better fixes anyone may have. Thanks.
...
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>
</dependencies>
</dependencyManagement>