posted 12 years ago
Hello,
I have some java code that calls native code library thru' JNI. So I have corresponding .h and .dll in the same directory as the class with native method declaration. This works fine in a simple Java project when I have testJNI.java in default package and testJNI.h and mydll.dll in same folder.
Now, in J2EE environment, where should this all go? If I put everything (.java, .class, .h and .dll) under one package - say com.abc.utils, it can't find that library at runtime giving me UnsatisfiedLinkError
What am I missing? Do I need to set somethings?
Thanks,
P.Ingle
I have some java code that calls native code library thru' JNI. So I have corresponding .h and .dll in the same directory as the class with native method declaration. This works fine in a simple Java project when I have testJNI.java in default package and testJNI.h and mydll.dll in same folder.
Now, in J2EE environment, where should this all go? If I put everything (.java, .class, .h and .dll) under one package - say com.abc.utils, it can't find that library at runtime giving me UnsatisfiedLinkError
What am I missing? Do I need to set somethings?
Thanks,
P.Ingle
Thanks,<br />P.Ingle
P. Ingle
Ranch Hand
Posts: 45
posted 12 years ago
No, I am calling native code from simple java class - a utility class.
My code works fine when .java is under default package and as soon as I move everything under com.abc.utils package, it fails to load the library.
So I guess the question is where do dll and .h go and do I need to set any classpath variable for it to find that .h and .dll from code under a package??
Thanks,
P.Ingle
My code works fine when .java is under default package and as soon as I move everything under com.abc.utils package, it fails to load the library.
So I guess the question is where do dll and .h go and do I need to set any classpath variable for it to find that .h and .dll from code under a package??
Thanks,
P.Ingle
Thanks,<br />P.Ingle
P. Ingle
Ranch Hand
Posts: 45
posted 12 years ago
ok, I tried following - they both fail at two different points
1.
have crypto.dll, jcrypto.h, jcrypto.class and jcrypto.java in same package com.abc.utils (jcrypto.java declares native methods,loads dll and has main method)
When I run it, it fails to find dll itself - failing at
System.loadLibrary("crypto");
giving me java.lang.UnsatisfiedLinkError: Can't find library crypto (crypto.dll) in java.library.path
By thw way, I also tried moving crypto.dll to c:\dllLib and running jaa code with Djava.library.path=C:\dllLib option - it gives me same error - can't find dll itself.
2. I moved crypto.dll at the same level directory com is
MyJNIProject
|
|-----com (and all package directories below it - com.abc.Utils)
|
|-----crypto.dll
com.abc.Utils has jcrypto.java, jcrypto.class, jcrypto.h
This way, it loads library, goes to 'main' but when I call the native method, it fails there giving me following error:
java.lang.UnsatisfiedLinkError: EncryptString
3.
Whole thing works smoothly when I have everything directly under MyJNIProject (jcrypto.java being in default package)
so MyJNIProject has jcrypto.java, jcrypto.class, jcrypto.h and crypto.dll
directly in it.
Any clue how to work it in case 1 and 2???

1.
have crypto.dll, jcrypto.h, jcrypto.class and jcrypto.java in same package com.abc.utils (jcrypto.java declares native methods,loads dll and has main method)
When I run it, it fails to find dll itself - failing at
System.loadLibrary("crypto");
giving me java.lang.UnsatisfiedLinkError: Can't find library crypto (crypto.dll) in java.library.path
By thw way, I also tried moving crypto.dll to c:\dllLib and running jaa code with Djava.library.path=C:\dllLib option - it gives me same error - can't find dll itself.
2. I moved crypto.dll at the same level directory com is
MyJNIProject
|
|-----com (and all package directories below it - com.abc.Utils)
|
|-----crypto.dll
com.abc.Utils has jcrypto.java, jcrypto.class, jcrypto.h
This way, it loads library, goes to 'main' but when I call the native method, it fails there giving me following error:
java.lang.UnsatisfiedLinkError: EncryptString
3.
Whole thing works smoothly when I have everything directly under MyJNIProject (jcrypto.java being in default package)
so MyJNIProject has jcrypto.java, jcrypto.class, jcrypto.h and crypto.dll
directly in it.
Any clue how to work it in case 1 and 2???

Thanks,<br />P.Ingle
