JNI noob question, and the whole thing too

Discussion in 'Java' started by drgonzo120, Oct 6, 2005.

  1. drgonzo120

    drgonzo120 Guest


    it's been 2 years since my last java-programming, and now i want
    restart my connection to the java-universe ... but hell.. has been that
    long ago ? i'm having trouble, not so much with the syntax and
    architecture, but rather with the typical compiling errors,
    classpath-shit & company, jre ? jdk ? , i'm using the eclipse

    so now i want to test the java JNI example that is online on the

    this is how my java directory in program files looks like:


    no where i can find javah.exe (how do you use that with eclipse anyway)
    only thing i can find is java.exe & javaw.exe , when i try the javah
    (which i couldn't find no where except for the j2ee directory:
    C:\Sun\AppServer\jdk\bin) but i guess my mind says so ,( i never did
    java except on school and studentjob and one time at my house, but
    don't remember) i need the java DEVELOPMENT kit and not the java
    RUNTIME environment ? N00b :p ) nothing to worry about i mumbled to
    myself and i cheated and copied the example code to the .h file .... so
    i'm in step 3 "create the header file")
    which looks like

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class HelloWorld */

    #ifndef _Included_HelloWorld
    #define _Included_HelloWorld
    #ifdef __cplusplus
    extern "C" {
    * Class: HelloWorld
    * Method: displayHelloWorld
    * Signature: ()V
    JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
    (JNIEnv *, jobject);

    #ifdef __cplusplus


    next trouble: how do i create a dll file without a c++ compiler ? i
    have the source code though ...:
    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>

    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
    printf("Hello world!\n");

    (i'm not gonna write the c code myself ) i can write c++ though, what
    is a good free compiler ? i don't have the dll file , i run w2k, is a
    dll file different for let's say xp and 98 ?

    this is what i can find on the creation of the dll file:

    On Microsoft Windows, the following command builds a dynamic link
    library hello.dll using Microsoft Visual C++ 4.0:

    cl -Ic:\java\include -Ic:\java\include\win32
    -LD HelloWorldImp.c -Fehello.dll

    and of course you guess it... i don't have visual mickey goes c++...
    dead end ...

    anyway, i wanted to run this code that was surely headed for distaster
    and got the error the guide predicted (woohoo for myself):

    java.lang.UnsatisfiedLinkError: no hello in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at HelloWorld.<clinit>(HelloWorld.java:6)
    Exception in thread "main"

    If you see an exception like the following, then you don't have your
    library path set up correctly.
    java.lang.UnsatisfiedLinkError: no hello in shared library path
    at java.lang.Runtime.loadLibrary(Runtime.java)
    at java.lang.System.loadLibrary(System.java)
    at java.lang.Thread.init(Thread.java)

    but the error just wants to say i don't have the dll file, i guess ...

    so anybody out there that wants to get me on track please ???

    thank you so much !!!
    drgonzo120, Oct 6, 2005
    1. Advertisements

  2. drgonzo120 wrote:
    Apparently you have installed several Java Runtime Environments (JREs),
    but no Java Delopment Kit. Installation of these would have given you a
    directory like these:
    The programs you look for (javah.exe, javac.exe, ...) are in the bin
    subdirectory of the above.
    Thomas Fritsch, Oct 6, 2005
    1. Advertisements

  3. drgonzo120

    drgonzo120 Guest

    yes, thanks, just downloaded the 5.0 JDK
    drgonzo120, Oct 6, 2005
  4. drgonzo120

    drgonzo120 Guest

    yes, thanks, just downloaded the 5.0 JDK
    drgonzo120, Oct 6, 2005
  5. drgonzo120

    drgonzo120 Guest

    maybe some one who could email me that dll ?

    drgonzo120, Oct 6, 2005
  6. drgonzo120 wrote:

    An alternative to "Microsoft Visual C++" is Cygwin (a bunch of
    Guessed correctly!
    Thomas Fritsch, Oct 6, 2005
  7. drgonzo120

    Roedy Green Guest

    in the jdk bin directory along with all the other tools.

    If you have windows you can find such things with the search files and
    directories function.
    Roedy Green, Oct 7, 2005
  8. drgonzo120

    Roedy Green Guest

    JNI is about writing C programs and gluing them into your Java code.
    If you don't know C or don't have a C /C++ compiler, you can't get
    Roedy Green, Oct 7, 2005
  9. drgonzo120

    drgonzo120 Guest

    Roedy Green schreef:
    i know c++, i just got me the borland c++ old version, but still am
    looking how to create the dll, gonna try the cygwin stuff

    thanks for the replies !!!
    drgonzo120, Oct 7, 2005
  10. On Thu, 06 Oct 2005 08:43:49 -0700, drgonzo120 wrote:

    Others have already addressed the "missing" javah and JDK-related portions
    of your post.

    To write JNI applications, you will absolutely need a compiler for
    whatever language the native portion is written in (in this case, C, or
    C++). For Windows your best bet is Microsoft's C++ toolchain, which is
    available (without the pretty GUI) for free on their website:


    Other options for windows include MinGW, which is capable of generating
    native executables and DLLs using the GNU compiler collection (gcc);
    however, setting up MinGW correctly can be a bit... involved. There are
    IDEs like Bloodshed's Dev-C++ that can make the task somewhat easier.
    Owen Jacobson, Oct 7, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.