[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


How to make an applet works with JNI?

Posted on 1998-02-11
Medium Priority
Last Modified: 2013-11-23
Dear Experts

I have an simple applet that construct a class that developed with C++. This class (C++) only print some message to screen using printf command.

Next, I compile the applet and produce *.class file.
I use javah utility to make header file.
Using Visual C++ v5.0, I create a *.dll file.
I store this file in same directory with *.class file.

Next, I make a jar file from this *.class to make it signed
I sign the jar file using javakey command

I test on appletviewer and it is working properly
Next I try using Hotjava 1.1 and see the result in HotJava Console. It is not working!

The exception thrown is:
java.lang.UnsatisfiedLinkError: hello

      at HelloApplet.init(HelloApplet.java:16)

      at sunw.hotjava.applet.AppletPanel.processEvent(AppletPanel.java:320)

      at sunw.hotjava.applet.AppletPanel.run(AppletPanel.java:293)

      at java.lang.Thread.run(Thread.java:474)

I have read the documentation on package index of JDK and this exception was produced because it can not find the *.dll file, but I store the file in the same directory with my *.jar file. I have tried to include this *.dll on my *.jar file but it still doesn't work.

I will be glad to hear your opinion and solution.
Thank you for your attention.

PT. Sigma Cipta Caraka
Jakarta - Indonesia
Question by:diamondo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2

Author Comment

ID: 1233012
Edited text of question

Expert Comment

ID: 1233013
The way the OS looks for a DLL is diffrent from the way that JAVA looks for class files.

If your problem is that the server cannot find the DLL then the most likley source of your problem is the PATH (not the CLASSPATH) environment variable.

The OS will look for a DLL in the same directory as the running application that invokes it first (The JAVA VM in this case) and then the path.

The way you can work arround the problem is to either place the DLL in a directory that allready appera in the PATH variable, or to add the directory where you are placing the DLL to the PATH and rebooting.

You could also place the DLL in the same directory as java.exe but this is a messy solution and should be avoided.

Let me know if this solves your problem. If it doesn't we can look at some other alternatives.

Author Comment

ID: 1233014
Yes, it's working when I access the HTML pages on the same machine with the *.dll files located. (PATH configured)

But when I move to another machine, use same browser and it throws same exceptions (UnsatisfiedLinkError: hello)

Is it means that in the client side have to install a *.dll file?
and configure PATH also?

Another issue is please review my source code:

// HelloApplet.java
import java.awt.*;
import java.applet.*;

public class HelloApplet extends Applet {

   public native void hello();
   static {
   public void paint(Graphics g) {
        try {
            g.drawString( "Hello World 1", 10, 10 );
            new HelloApplet().hello();
            g.drawString( "Hello World 2", 10, 20 );
        catch (Exception e) {
            System.out.println( "Exception: " + e.toString() );
            g.drawString( "Exception: " + e.toString(), 10, 30);

/* HelloApplet.cpp */

JNIEXPORT void JNICALL Java_HelloApplet_hello(JNIEnv * env, jobject obj) {
   printf("Hello! This is my first Applet using Native Methods!\n");

The problem is: The Browser prints Hello World 1 and Hello World 2 successfully without throws any exceptions, but when I see the HotJava Console Window, I cannot find "Hello! This is my first Applet Using Native Methods!" message.

So Is Native Code executed or not?

Thank you for your advice, I'm realy appreciated.


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1233015
Addition: I try using appletviewer and it's working perfectly.
          I see my Hello World 1 and Hello World 2 on the appletviewer window and my "Hello! This is my first..." on the DOS Prompt Window.

Once again, thank you very much.

Expert Comment

ID: 1233016
If I uderstand what you are doing correctly then yes, the .dll file must be installed in the clients machine. It must also be installed in a directory that is included in the client machines PATH or whoms directory is precisley specified  in the System.loadLibrary() call, for instance:


Of course, this implies that the dll is actualy stored at that location.

How you actualy deploy the dll is a matter of choice. The most common way of acomplishing it is to include the dll in a signed jar file. In this fashion you can download the .dll to your local browser cache directory as a trusted file and avoid several security box issues that can cause problems for you in more complicated JNI dll's.

The problems with this approach are that you need a class 2 or better Verisign signature and that the procedure to actualy sign the JAR file changes from browser to browser.

Another option of course, is to use a setup program and have the user download and execute it before loading your pages. This has the disadvantages of forcing your user to take extra steps in loading your product plus making upgrades much more disfficult.

Other alternatives include the use of server side includes, servlets or making socket calls to the server in order to call the DLL at the server or using either RMI or CORBA to make the call. Each one has its own set of advantages and disadvantages from increased networking traffic to more complicated programming and are not realy recomended for an applet the size of the one you are writting.

The main point though is that the client must either have the DLL file stored localy or you must establish a mechanism by which the client can either pre-load the DLL file or access it via remote proccesing of some kind.


Author Comment

ID: 1233017
I have a copy of DLL file and store in particular directory on client machine
I have added that directory to PATH variable on client machine

When I try to load an applet (hotjava browser and appletviewer) on the server, it still throws UnsatisfiedLinkError exception

Could you explain something wrong with this?
I put the applet on jar files and signed with javakey.


Accepted Solution

ashishagarwal earned 300 total points
ID: 1233018
have you set up up Library path ?????

you need to set it up:

on unix it is:
%setenv LD_LIBRARY_PATH mylibrarypath

similarly you can set it ofr windows!!

hope it helps

Author Comment

ID: 1233019
Yes I did in Windows environment.
Based on jpk's answer, I added DLL file location to my PATH variable but still doesn't work. Any other idea?

Point to tutorial is appreciated, Thank you.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

650 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