Solved

Java native Interface

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array11 challenge 16 52
parentbit challenge 3 52
HashMap Vs TreeMap 12 49
Eclipse Neon and jdk 1.8.0 11 72
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

760 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

26 Experts available now in Live!

Get 1:1 Help Now