• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI Invocation Debugging  RSS feed

Markus Moos
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!