wood burning stoves 2.0*
The moose likes Java in General and the fly likes JNI Invocation Debugging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI Invocation Debugging" Watch "JNI Invocation Debugging" New topic

JNI Invocation Debugging

Markus Moos

Joined: Jun 06, 2002
Posts: 4
I work on a pretty complex native application which loads a dll. This dll starts the jvm by the jni invocation api and executes some java classes. The classes perform some native callbacks into the dll.
The invocation of the jvm and the of my java programm works fine. The problem is that I can't debug my java classes. As described in some jni tutorials I invoke the jvm from my dll with the debug options. Then I try to connect to the jvm with a java debugger which results in a ConnectException.
To reduce the complexity I wrote a little exe containing the invocation code (see at code listening at the end). Unfortunatly I have the same results. The problem is that if I start the java class with the java.exe and with the same options as in the exe everything is ok. I can connect with my debugger and debug the code.
Has anyone an idea what the problem could be and what's the difference in calling a java programm by the invocation api or by the java.exe.
Thanks for any suggestions
The code of the test exe:
int main() {
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[5];
jint res;
jclass cls;
jmethodID mid;
jstring jstr;
jobjectArray args;
options[0].optionString = "-Djava.class.path=I:/Vorprojekte/InvokeJVM/java/classes";
options[1].optionString = "-Djava.compiler=NONE"; /* disable JIT */
options[2].optionString = "-Xdebug"; /* print JNI-related messages */
options[3].optionString = "-Xnoagent";
options[4].optionString = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y";

vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 1 ;
vm_args.ignoreUnrecognized = JNI_FALSE;

/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm,(void**) &env,&vm_args);
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
cls = (*env)->FindClass(env, "Prog");
if (cls == 0) {
fprintf(stderr, "Can't find Prog class\n");

mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String V");
if (mid == 0) {
fprintf(stderr, "Can't find Prog.main\n");
jstr = (*env)->NewStringUTF(env, " from C!");
if (jstr == 0) {
fprintf(stderr, "Out of memory\n");
args = (*env)->NewObjectArray(env, 1,
(*env)->FindClass(env, "java/lang/String"), jstr);
if (args == 0) {
fprintf(stderr, "Out of memory\n");
(*env)->CallStaticVoidMethod(env, cls, mid, args);

return 0;
I agree. Here's the link: http://aspose.com/file-tools
subject: JNI Invocation Debugging
Similar Threads
JNI : undefined reference to JNI_CreateJavaVM()
JNI_CreateJavaVM returns error
problem of C++ Call java with JNI
JNI_CreateJavaVM returns with -1
Invoking JVM through C++ code