exception in thread main java.lang.unsatisfiedlinkerror no in java.library.path
Posted by Sayan Guharoy
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jacob-1.17-M2-x64 in java.library.path
Or
Can't load AMD 64-bit .dll on a IA 32-bit platform
Or
No Class Def. error (Project specific)
You may get one of the above exceptions due to a list of anomalies that I will discuss one by one.
1. You haven’t followed the trio true method. Always go for a trio true setup like below
OS
|
JAVA
|
JACOB
|
Business Env recommendation
|
64 bit
|
1.6 64 bit jdk,jre
|
jacob-1.17-M2-x64.dll
|
YES
|
64 bit
|
1.7 64 bit jdk,jre
|
jacob-1.17-M2-x64.dll
|
NO
|
32 bit
|
1.6 32 bit jdk,jre
|
jacob-1.17-M2-x86.dll
|
YES
|
To check OS version and bit
Press winkey + pause
Check system type and windows edition (windows 7 tested)
To check JAVA version and bit
Type java -version in command prompt. If you receive a message like 'not recognized as an internal or external command' then set the following in your environment variables
1.PARAM:PATH/VALUE:"C:\Program Files\Java\jdk1.6.0_32\bin"
2.PARAM:JAVA_HOME/VALUE:"C:\Program Files\Java\jdk1.6.0_32"
To check Java bit after typing java -version check for the following messages
if message displays 64 Bit server VM then it is a 64 bit jvm.
if message displays client VM the it is a 32 bit jvm.
2. Your Jacob dll is missing under windows/system32 directory.
3. You are not loading Jacob dll from system32 directory rather you are loading it externally created folder
Which you can do buy two ways
1. In Eclipse under run/debug under vm arguments you have mentioned like
-Djava.library.path="C:\lang\java\jacob-1.17-M2"2. You have used command prompt option and added runtime library as shown below
Java -Djava.library.path="C:\lang\java\jacob-1.17-M2" -cp .;C:\lang\java\jacob-1.17-M2\jacob.jar;C:\lang\java\jacob-1.17-M2 Outlook
Here is the full script if you are compiling and running through cmd
@echo off "C:\Program Files\Java\jdk1.6.0_32\bin\javac.exe" -cp .;C:\lang\java\jacob-1.17-M2\jacob.jar "C:\lang\java\jacob-1.17-M2\Outlook.java" java -Djava.library.path="C:\lang\java\jacob-1.17-M2" -cp .;C:\lang\java\jacob-1.17-M2\jacob.jar;C:\lang\java\jacob-1.17-M2 Outlook pause
but your path is wrong.
Terms to note
Cp refers to your classpath directories where the compiler will look for user created classes, this can be setted also through environment variables as “CLASSPATH” and value in this case will be
C:\lang\java\jacob-1.17-M2\jacob.jar;C:\lang\java\jacob-1.17-M2
Path refers jdk bin folder
Java_home should be jdk root folder
WORKAROUND
Check if any of the above mentioned scenarios matches your case .Do a test run at this point, if unsuccessful proceed.
1. Add jacob-1.17-M2-x64.dll to
2. Place Jacob.jar in your WEB-INF/lib folder.
Do a test run at this point, if unsuccessful proceed.
3. Add this statement to your java code before you initiate your Jacob component
Relative path:
System.loadLibrary("jacob-1.17-M2-x64");
Note: Don’t use extension in case of Load Library method. This load will search under windows/system32 folder.
OR
You can give absolute path and use an external source for the dll.
System.load("C:\\jacobdll\\jacob-1.17-M2-x64.dll") ;
4. Set your JRE path to 1.7 in your project properties under JRE tab.
5. You can test run using the following code snippet
import com.jacob.com.*;
import com.jacob.activeX.*;
public class Outlook {
public static void main(String[] args) {
System.out.println("Outlook: IN");
System.load("C:\\jacobdll\\jacob-1.17-M2-x64.dll") ;
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
try {
System.out.println("version="+axOutlook.getProperty("Version"));
Object oNameSpace = axOutlook.getProperty("Session").toDispatch();
System.out.println("oNameSpace=" + oNameSpace);
} finally {
axOutlook.invoke("Quit", new Variant[] {});
}
}
}
JDK,JRE 1.6 64 bits
http://www.oracle.com/technetwork/java/javase/downloads/jdk6u37-downloads-1859587.html
JRE 1.7 64 bits
http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1637588.html
Jacob jar + dll 64 bits.
http://sourceforge.net/projects/jacob-project/
Thanks on commenting on my post How to fix Exception in thread main java.lang.unsatisfiedlinkerror no in java.library.path. I see you have also done a good job to explain this. keep it up.
ReplyDeleteJavin
Thanks Javin
ReplyDelete