Solved

Java native Interface

Posted on 1997-04-01
2
671 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
nextBoolean(double p) for Random class 3 41
javap not working 8 58
Java syntax, or is it Selenium 6 30
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

856 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