Solved

Java native Interface

Posted on 1997-04-01
2
663 Views
Last Modified: 2013-11-23
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?
0
Comment
Question by:haresh
2 Comments
 
LVL 1

Accepted Solution

by:
trof earned 150 total points
ID: 1219360
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.
0
 

Expert Comment

by:Ferris
ID: 1219361
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...
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now