Jacob 1.14.3 DLL no detected by the java.libary.pa

2019-09-02 09:22发布

问题:

I am trying to implement the library JACOB to communicate to some payments devices such as PINPADs. I have created a java project but when the main class execute the method that use the DLL in the runtime gives a error no jacob-1.14.3-x64 in java.library.path

Here you can find what I am using to build the project:

  • Operating System: Windows 10 64bit
  • JRE/JDK version: 1.8.0_181 64bit*( changed from 32 to 64bit )*
  • Eclipse: Photon Release (4.8.0)
  • Maven version: 3.5.4
  • JACOB version: 1.14.3 (Both files 64[x64] and 32[x86])

Here you can find the solutions that I already have try

  • Add the jacob.jar as external library and add the folder where the dlls as native library.
  • Use the command for the java library path –Djava.library.path=C:\Users\adazat\Downloads\ClienteImplantadoJava\jacob-1.14.3\

  • Added the dll files to /Java/jdk/jre/bin and /Java/jdk/jre/lib/ext

  • Added the dependencies using maven commands

mvn install:install-file -Dfile=C:\Users\adazat\Downloads\ClienteImplantadoJava\jacob-1.14.3\jacob-1.14.3-x64.dll -DgroupId=jacob -DartifactId=jacob-dll -Dversion=1.14.3 -Dpackaging=dll -DgeneratePom=true


mvn install:install-file -Dfile=C:\Users\adazat\Downloads\ClienteImplantadoJava\jacob-1.14.3\jacob.jar -DgroupId=jacob -DartifactId=jacob-jar -Dversion=1.14.3 -Dpackaging=jar -DgeneratePom=true

  • Added the dependencies to maven pom.xml

I have searched in different questions in stack-overflow and still does not work trying any approach, I would like to know if some has a kind of similar problem and what else iI could try, to solve it. I really appreciate your time :D

回答1:

Just for reference, to your intitial question: Switch to a 64Bit JDK since a 64Bit dll can not be called from a 32bit jre/jdk.

Regarding your next error:

Can't co-create object

Before using a COM object, it must be registered in the system (e.g. its CLSID or ProgID must exist in the Windows Registry). If its not registered, regasm.exe utility can be used to do that:

Use: Regsvr32 PathToDll

Or you may also try: %systemroot%\Microsoft.NET\Framework64\vX.X\RegAsm.exe /verbose /nologo /codebase PINPAD.dll

(replace vX.X with the version installed on your system e.g. v3.0 or v4.0.30319. If you want to use the 32bit dll use ...\Framework\... instead of ...\Framework64\...)

Once it’s registered CoCreateInstance() API method can be used to obtain a reference to an interface exposed by the object and call its methods. Furter details can be found here.



回答2:

You have to verify if the java.library.path is correct.

I was writing -Djava.library.path="C:\Users\adazat\Downloads\ClienteImplantadoJava\jacob-1.14.3\"; and -Djava.library.path=C:\Users\adazat\Downloads\ClienteImplantadoJava\jacob-1.14.3\; you have to make sure that you are not using

  • "" to surround the path
  • ; at the end
  • and that should be \ at the end of the path to indicate that is a folder that contains the dlls.

After I resolved it, now I am getting the following error when is program is executed.

com.jacob.com.ComFailException: Can't co-create object