Results 1 to 5 of 5
  1. #1
    Sungron is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default How to create the Jvm using JDK?

    Hello guys,
    Im looking for a tutorial about creating jvm from C++ code...
    I already tried google, etc, but I found only one code snippet that unfortunatelly doesnt work:
    Java Code:
    #include <jni.h>
    #include <conio.h>
    #include <iostream>
    #pragma comment(lib,"jvm.lib");
    #include <stdio.h>
     
     
    JNIEnv* create_vm() {
    JavaVM* jvm;
    JNIEnv* env;
    JavaVMInitArgs args;
    JavaVMOption options[1];
     
    / *There is a new JNI_VERSION_1_4, but it also doesnt work.* / 
    args.version = JNI_VERSION_1_2;
    args.nOptions = 1;
    options[0].optionString = "-Djava.class.path=c:\\projects\\local\\inonit\\classes";
    args.options = options;
    args.ignoreUnrecognized = JNI_FALSE;
     
    JNI_CreateJavaVM(&jvm, (void )&env, &args); //exit with code 1 (0x1)
    return env;
    }
    int main(int argc, char **argv) {*
    *JNIEnv* env = create_vm();
    //invoke_class( env );
    system("pause");
    }
    It quits at JNI_CreateJavaVM(&jvm, (void )&env, &args);
    - The program '[3084] test.exe: Native' has exited with code 1 (0x1).
    anyone know why? Or can help me somehow with solving this problem?
    I tried chaning options[0].optionString to path to the classes stuff of jdk examples but it doesnt change anything...
    any help appreciated...
    Sungron.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default

    After a first read it all looks sensible, except for this line:

    Java Code:
    JNI_CreateJavaVM(&jvm, (void)&env, &args);
    Shouldn't that be:

    Java Code:
    JNI_CreateJavaVM(&jvm, (void** )&env, &args);
    kind regards,

    Jos

  3. #3
    Sungron is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Java Code:
    JNI_CreateJavaVM(&jvm, (void)&env, &args);
    Ah, of course, such code would give compile error... I just somehow missed two '*' while posting code here :)
    btw, Im using Microsoft Visual C++ 2008 Express Edition on windows vista... maybe It can cause problem....? I tried diffrent project settings, but app still exits with 0x1

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Sungron View Post
    Ah, of course, such code would give compile error... I just somehow missed two '*' while posting code here :)
    btw, Im using Microsoft Visual C++ 2008 Express Edition on windows vista... maybe It can cause problem....? I tried diffrent project settings, but app still exits with 0x1
    I googled a bit on "JNI_CreateJavaVM" and "create jvm from c" and they all mention and show (working) examples similar to your example. Maybe Google can be a bit of help ...

    kind regards,

    Jos

  5. #5
    Sungron is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    Hmm,do anyone here a working example of jvm creation?
    I must have the "classes" stuff ... but there isnt a lot of tutorials about creating it
    Last edited by Sungron; 02-01-2010 at 12:25 PM.

Similar Threads

  1. please help me to create setup
    By javastuden in forum AWT / Swing
    Replies: 4
    Last Post: 11-10-2009, 06:58 AM
  2. How to create an index for the
    By suneelakulkarni in forum Lucene
    Replies: 0
    Last Post: 07-13-2009, 04:23 PM
  3. How to create animation
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 09:43 PM
  4. Create XML From XSD
    By Jack in forum XML
    Replies: 1
    Last Post: 07-09-2007, 01:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •