• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 712
  • Last Modified:

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)

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?
1 Solution
The problem is: MS did not implement native methods call correctly. Another example - calling JDBC from  J++. Compilation is perfect, but when JView.exe calls JDBC/ODBC bridge and dives into native method - die . I'm pretty sure, if you will evecute you byte code by java.exe (not JView.exe) everything will run perfectly. So, the solution is: compile in any enviroment, run in Java.exe, or, if performance really important, in Symantec JIT-compiler.
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...

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now