Hi:
   I was trying to write a windows service for bajie http server.   I am
using VC++ 5.0 on windows XP,
and JDK 1.3.1.  (JDK 1.4 is also installed, but are not used).

    When I try to execute the code below, I got the error -1 when
JNI_CreateJavaVM is called.
    (If I use JavaVM1_1InitArgs structure, I got error -3).


     Can someone tell me what is wrong with the code?  I was just using the
code from java.sun.com's
example, with a little bit of modification.

     Thank you!
     Gang

     Here is the code to invoke the jvm from native code:

// jinvoker.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "windows.h"

#include <jni.h>
#define PATH_SEPARATOR ';'
#define USER_CLASSPATH "."

void main() {
    JNIEnv *env=NULL;
    JavaVM *jvm;
    jint res;
    jclass cls;
    jmethodID mid;
    char classpath[1024];


    /* IMPORTANT: specify vm_args version # if you use JDK1.1.2 and beyond
*/
    JavaVMInitArgs vm_args;
     JavaVMOption options[1];
     options[0].optionString =
         "-Djava.class.path= d:\\httpsrv\\jzHttpSrv.jar;d:\\lib\\rt.jar";
     vm_args.version = 0x00010002;
     vm_args.options = options;
     vm_args.nOptions = 1;
     vm_args.ignoreUnrecognized = JNI_TRUE;


    JNI_GetDefaultJavaVMInitArgs(&vm_args);

    /* Append USER_CLASSPATH to the end of default system class path */
    //sprintf(classpath, "%s%c%s",
    //        vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
    //vm_args.classpath = classpath;

    /* Create the Java VM */
    //fail right here with error code -1.
    res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);
    if (res < 0) {
        fprintf(stderr, "Can't create Java VM %i\n",res);
        exit(1);
    }

    jvm->DestroyJavaVM();
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to