You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Leon Palermo <le...@zedak.com> on 2000/11/01 13:18:05 UTC
Re: IIS, tomcat and java ...
You need to use JNI to access the methods in the .dll. If you have already
done that from an application, create a jsp or servlet that uses the class
and call the appropriate methods.
Here is a quick example of a Java class that calls native .dll:
public class DllTest{
//Two native method from the 'mydll.dll'
public native String[] returnTestArray();
public native String getTestString();
static{
System.loadLibrary("mydll");
}
//Test the native methods and print results to ServletOutputStream
public static void test(ServletOutputStream out) {
DllTest newDll = new DllTest();
out.println(newDll.getTestString());
String[] ar = newDll.returnTestArray();
for (int i=0; i<5; i++) {
out.println("array element"+i+ "=" + ar[i]);
}
}
}
Here are the methods in C++ using JNI:
#include "stdafx.h"
//JNI header
#include "jni.h"
//Notice I create a header file to use from my preious
//Java class using 'javah' utility
#include "DllTest.h"
JNIEXPORT jobjectArray JNICALL Java_ArrayHandler_returnArray
(JNIEnv *env, jobject jobj){
jobjectArray ret;
int i;
char *message[5]= {"first",
"second",
"third",
"fourth",
"fifth"};
ret= (jobjectArray)env->NewObjectArray(5,
env->FindClass("java/lang/String"),
env->NewStringUTF(""));
for(i=0;i<5;i++) {
env->SetObjectArrayElement(ret,i,env->NewStringUTF(message[i]));
}
return(ret);
}
JNIEXPORT jstring JNICALL Java_ArrayHandler_lastFile
(JNIEnv *env, jobject){
return env->NewStringUTF("Test String");
}
Here is a .jsp file that calls the class which calls the .dll:
<%@ page session="false"%>
<html>
<body>
<%DllTest.test(out);%>
</body>
</html>
The results should be:
Test String
array element0=first
array element1=second
...
I hope all of this helps. And don't worry about the English; I am sure I
don't speak your language well either.
Leon Palermo
Zedak Corporation
Valhalla, NY
> hi all :
>
> This is the first time i write (and i don speak a good english, sorry
all )
>
> I have a .dll and i need know how acces at methods of this dll with java
...
> My first step is with a java aplication (simple), create a instnace of the
.dll, but i don know how
> i do ...
>
> do you undertendme ??
> Thanks ...
> Sorry for my bad english i need pratice ... =-(