Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JNI noob question, and the whole thing too

1 view
Skip to first unread message

drgonzo120

unread,
Oct 6, 2005, 11:43:49 AM10/6/05
to
Hello,

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
thingie...

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

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

java/j2re1.4.2
java/j2re1.4.2_06
java/jre1.5.0_02
java/jre1.5.0_04

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" {
#endif
/*
* Class: HelloWorld
* Method: displayHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

********************

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>

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
******


(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
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 !!!

Thomas Fritsch

unread,
Oct 6, 2005, 12:19:57 PM10/6/05
to
drgonzo120 wrote:
[...]

>
> this is how my java directory in program files looks like:
>
> java/j2re1.4.2
> java/j2re1.4.2_06
> java/jre1.5.0_02
> java/jre1.5.0_04
>
> 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
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:
java/j2sdk1.4.2
java/j2sdk1.4.2_06
java/jdk1.5.0_02
java/jdk1.5.0_04
The programs you look for (javah.exe, javac.exe, ...) are in the bin
subdirectory of the above.

>
[...]

--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

drgonzo120

unread,
Oct 6, 2005, 12:27:27 PM10/6/05
to
yes, thanks, just downloaded the 5.0 JDK

drgonzo120

unread,
Oct 6, 2005, 12:39:43 PM10/6/05
to

drgonzo120

unread,
Oct 6, 2005, 12:41:33 PM10/6/05
to
maybe some one who could email me that dll ?


drgon...@yahoo.com


thanks

Thomas Fritsch

unread,
Oct 6, 2005, 12:43:12 PM10/6/05
to
drgonzo120 wrote:

[...]


>
> 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 ...

An alternative to "Microsoft Visual C++" is Cygwin (a bunch of
GNU/Linux-like tools running on Windows). See <http://www.cygwin.com/>.
It comes with a gcc.exe (the GNU C/C++ compiler) and it can make DLLs.
>
[...]


>
> ***
> 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
> at java.lang.Thread.init(Thread.java)
> ***
>
>
> but the error just wants to say i don't have the dll file, i guess ...

Guessed correctly!

Roedy Green

unread,
Oct 7, 2005, 12:32:47 AM10/7/05
to
On 6 Oct 2005 08:43:49 -0700, "drgonzo120" <drgon...@yahoo.com>
wrote or quoted :

>no where i can find javah.exe

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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Roedy Green

unread,
Oct 7, 2005, 12:35:26 AM10/7/05
to
On 6 Oct 2005 08:43:49 -0700, "drgonzo120" <drgon...@yahoo.com>
wrote or quoted :

>(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:

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
anywhere.

drgonzo120

unread,
Oct 7, 2005, 9:47:22 AM10/7/05
to

Roedy Green schreef:

> On 6 Oct 2005 08:43:49 -0700, "drgonzo120" <drgon...@yahoo.com>
> wrote or quoted :
>
> >(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:
>
> 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
> anywhere.
> --

> Canadom Again taking new Java programming contracts.

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 !!!

Owen Jacobson

unread,
Oct 7, 2005, 10:33:42 AM10/7/05
to
On Thu, 06 Oct 2005 08:43:49 -0700, drgonzo120 wrote:

<snip>


> 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 ....

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

<snip>

> 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
> *****

<snip>

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

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:

<http://msdn.microsoft.com/visualc/vctoolkit2003/default.aspx>

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.

0 new messages