JNI noob question, and the whole thing too

D

drgonzo120

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

Thomas Fritsch

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.
[...]
 
D

drgonzo120

maybe some one who could email me that dll ?


(e-mail address removed)


thanks
 
T

Thomas Fritsch

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 said:
[...]

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

Roedy Green

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

Roedy Green

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

drgonzo120

Roedy Green schreef:
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.

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

Owen Jacobson

On Thu, 06 Oct 2005 08:43:49 -0700, drgonzo120 wrote:

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.

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

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top