Search code examples
scalaintellij-ideatesseractjaitess4j

"Need to install JAI Image I/O package." error when using tess4j in IntelliJ IDEA Scala SBT project


The below tess4j JARs are part of my Scala SBT project in IntelliJ IDEA and are also added as module dependencies:

enter image description here

However, I get a java.lang.RuntimeException: Need to install JAI Image I/O package. https://java.net/projects/jai-imageio/ exception when trying to run the following code in a Scala worksheet:

import java.io.File
import net.sourceforge.tess4j._

val imageFile = new File("LinkToJPGFile")
val instance = new Tesseract()
instance.setDatapath("MyTessdataFolder")

val result = instance.doOCR(imageFile)
print(result)

even though jai-imageio-core-1.3.1.jar is properly included in the project.


Solution

  • Instead of trying to add the JARs individually, add the below line to your build.sbt:

    // https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j
    libraryDependencies += "net.sourceforge.tess4j" % "tess4j" % "3.3.1"
    

    Or whichever version you are using found at https://mvnrepository.com/artifact/net.sourceforge.tess4j/tess4j