Link to home
Start Free TrialLog in
Avatar of haresh
haresh

asked on

Java native Interface

I am trying to call a native (32bit Windows) function from Java code.

My Platform:
  Windows 95
  Using MSJ++ to write java code.
  Using MSVC++ 4.0 to write 32bit windows Dll.
  Using JDK 1.1.1
  JView.exe is commandline loader from MSJ++,   version 1.00.6211  .

Actually I am using HelloWorld sample for JNI. (This sample is in following
page of Javasoft)
      http://www.javasoft.com:80/products/jdk/1.1/docs/guide/jni/index.html

So both java code and windows dll compile well.
When I try to run Java program,
c:\....\jview main
it loads the native windows dll (as the dll's DllMain gets called.). Then
the Java code then tryies to call a native function from the DLL.
I get following error message in DOS shell.
Error:  java.lang.UnsatisfiedLinkError
(Thats it. No more description. about error)

What is the problem? How do I solve this.
What happens in Java code is, it loads windows dll. Then it calls a function of the dll.
is any mapping between the function being called from Java and the function in Dll, is required?
ASKER CERTIFIED SOLUTION
Avatar of trof
trof

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ferris
Ferris

haresh, in my documentation, it says a java.lang.UnsatisfiedLinkError occurs when your path doesn't contain the current directory.

For instance, if you have the dll local to the class file you're trying to run in order to make the native call and your current directory is not in your path, the System.loadLibrary("dll"); statement will fail as the java program cannot find the dll.

Either move the dll to a place in your current path or add a .; to your current path statement in your autoexec.bat found in the root of c:.  

What I do ( as I have many projects on the go ) is to create two .bat files to update my path and classpath settings for each project.  Depending on my current working directory or whether I need to point to JDK1.02 or JDK1.1.1 (when doing a javac), I run the batch files to avoid problems like what you're having.  It's important to set the path for each DOS Shell that you're using.  For instance, the following is my sp11.bat (set path for jdk1.1):

set path=.;c:\windows;c:\windows\command;c:\dos;d:\notes;c:\nwclient;c:\bats;c:\util;c:\jdk1.1\bin;c:\jdk1.1\include;c:\jdk1.1\lib

Similarly, here is sp10nvc.bat (set path for jdk102 without Visual Cafe path info)

set path=.;c:\windows;c:\windows\command;c:\dos;d:\notes;c:\nwclient;c:\bats;c:\util;c:\java\bin;c:\java\lib;c:\java\include;d:\dev\devstudio\myprojects\native

You can always check your current path and classpath settings using set |more in your current DOS window...

Setting the classpath is done in a similar way.

By the way, I'm using almost an identical setup as you are:

Win95, MSJ++1.1, MSVC++5.0, JDK1.0.2 and JDK1.1.1

I had the same UnsatisfiedLinkError(s) and fixing the path (for me) fixed the problem...

Hope this helps...