[FREngine 11] maven is not supported

  • 917 Views
  • Last Post 20 November 2015
zeljkoar posted this 09 November 2015

Hello,

I am using Java API and my project is Maven project. I have installed com.abbyy.FREngine.jar into local repository. Everything was fine until I didn't try to run my code. I get following exception

java.lang.UnsatisfiedLinkError: Can't load library: C:\ProgramData\ABBYY\SDK\11\FineReader Engine\win\x64\FREngine.Jni.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.abbyy.FREngine.Engine.unpackJarAndLoadFREngineJNIDll(Engine.java:203)
at com.abbyy.FREngine.Engine.loadFREngineJNIDll(Engine.java:157)
at com.abbyy.FREngine.Engine.GetEngineObject(Engine.java:30)

At first I wasn't sure what went wrong, because same code was working fine before I have put com.abbyy.FREngine into Maven repository, but after much hours spend digging what is wrong I have decided to decompile com.abbyy.FREngine.jar. What I have found there was really disturbing. You guys are unpacking jar file it self and are using URLClassLoader to get all loaded jar and then you are matching you jar by the name which in my case is changed to com.abbyy.FREngine-11.jar (because of Maven).

/*     */   private static void unpackJarAndLoadFREngineJNIDll() throws Exception
/*     */   {
/* 165 */     String str1 = null;
/* 166 */     ClassLoader localClassLoader = Engine.class.getClassLoader();
/*     */     
/* 168 */     if ((localClassLoader instanceof URLClassLoader)) {
/* 169 */       localObject = (URLClassLoader)localClassLoader;
/* 170 */       for (java.net.URL localURL : ((URLClassLoader)localObject).getURLs()) {
/* 171 */         String str3 = localURL.toString();
/* 172 */         if (str3.indexOf("com.abbyy.FREngine.jar") > 0) {
/* 173 */           int k = "file:/".length();
/* 174 */           int m = str3.length();
/* 175 */           str1 = str3.substring(k, m);
/* 176 */           str1 = str1.replace("%20", " ");
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 181 */     Object localObject = GetJNIDllFolder();
/* 182 */     if (!canWriteToDir((String)localObject)) {
/* 183 */       throw new Exception("Can't access to the JNI dll folder: \"" + (String)localObject           + "\". Use method SetJNIDllFolder to set the correct path.");
/*     */     }
/*     */     
/*     */ 
/* 187 */     if (str1 != null) {
/*     */       try {
/* 189 */         localObject = combinePaths((String)localObject, "Java");
/* 190 */         createPath((String)localObject);
/* 191 */         localObject = combinePaths((String)localObject, "com.abbyy.FREngine");
/* 192 */         createPath((String)localObject);
/*     */         
/* 194 */         unpackJar(str1, (String)localObject, platformShortName);
/*     */       }
/*     */       catch (IOException localIOException) {}
/*     */     }
/*     */     
/*     */ 
/* 200 */     String str2 = combinePaths((String)localObject, platformShortName);
/* 201 */     str2 = combinePaths(str2, getJVMArchitecture());
/* 202 */     str2 = combinePaths(str2, jniDllName);
/* 203 */     System.load(str2);
/*     */   }

This is very bad practice from various reasons.And this absolutely blocks anyone who use Maven. You could simply use getClass().getResourceAsStream(name) to get necessary dlls.

Please advice how to proceed further.

Thanks, Zeljko

  • Liked by
  • maol
Order By: Standard | Newest | Votes
zeljkoar posted this 10 November 2015

Solution for this is simple but not very elegant. I have to add com.abbyy.FREngine.jar into repository as following:

mvn install:install-file -Dpackaging=jar -DgeneratePom=true -Dclassifier=win -DgroupId=com.abbyy.FREngine -DartifactId=com.abbyy.FREngine.jar -Dversion=11 -Dfile=com.abbyy.FREngine.jar

In that case my dependency in pom.xml looks like this:

<dependency>
 <groupId>com.abbyy.FREngine</groupId>
 <artifactId>com.abbyy.FREngine.jar</artifactId>
 <version>${abbyy.version}</version>
 <classifier>${os.prefix}</classifier>
</dependency>

In this configuration jar in repository has name like com.abbyy.FREngine.jar-11-win.jar, so unpackJarAndLoadFREngineJNIDll() method will work fine.

maol posted this 20 November 2015

I had the same problem. I extracted the dll manually from the jar file and then copied the dll to C:\ProgramData\ABBYY\SDK\11\FineReader Engine\win\x64\

Note that you can copy the dll somewhere else and call Engine.SetJNIDllFolder(jniDllFolder) to set the parent folder of win\x64\FREngine.Jni.dll

Close