Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

can't create java vm ... setting path for jvm.dll

843829Apr 4 2006 — edited Apr 6 2006
hi

I have compiled the invoke.c program correctly but when i run the program it gives run time error: can't create java vm.

i have made the path changings in control panel >>> environment variable..... but still it is giving the same error.
i have also changed my project >>> setting >>> link >> jvm.lib

is there anyother place i have to make changes for jvm.dll ??

thanks

Comments

843829
can we dynamically link jvm.dll using command line (cl) option?
843829
or how can we directly embed the jvm.dll path in the code?
a simple code will be helpful

jvm.dll is in the path: c:\program files\java\jdk1.5.0_06\jre\bin\client

thanks again
843829
how do i create a new post?
843829
step 1: click on the following link:
http://forum.java.sun.com/index.jspa
step 2: login with your login name & password
step 3: click on the "native methods" forum on the new page which appears after login
step 4: click on the "post new topic" button

voil�
843829
can we dynamically link jvm.dll using command line (cl) option?
You mean statically link, right? And it's with link.exe and not cl.exe.
But you can also dynamically load jvm.dll at runtime of course.
or how can we directly embed the jvm.dll path in the code?
a simple code will be helpful
Yes you could load dynamically jvm.dll with its absolute path but it would not be very useful on machines other than yours, right?

To be able to use the JNI invocation API, you need to "find" statically or dynamically the JNI_CreateJavaVM function.

** Statically **:

To build:
// C code (very simple example without error checking):

JavaVM * jvm = NULL;

jint create_jvm()
{
    JavaVMInitArgs vm_args;
    JavaVMOption options[1];
    JNIEnv * env;
    
    options[0].optionString = "-Djava.class.path=.";
    
    vm_args.options = options;
    vm_args.nOptions = 1;
    vm_args.version = JNI_VERSION_1_4;
    vm_args.ignoreUnrecognized = JNI_FALSE;
    
    return JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
}
// Compiler settings to your Visual Studio project:
Configuration properties|C/C++|General|Additional Include Directories: {jdk_root_folder}\include\win32;{jdk_root_folder}\include
// Linker settings to your Visual Studio project:
Configuration properties|Linker|Input|Additional Dependencies: jvm.lib ( located in {jdk_root_folder}\lib )

To run:

Add to the Path environment variable the jvm.dll location
Path=C:\Program Files\Java\jre1.5.0_06\bin\client;%Path%


** Dynamically **:

To build:
// C code (very simple example without error checking):

typedef jint (*type_JNI_CreateJavaVM)(JavaVM ** pJvm, JNIEnv ** pEnv, void * vmArgs);

HINSTANCE hLib = NULL;
JavaVM * jvm = NULL;

jint create_jvm()
{
    type_JNI_CreateJavaVM fct_JNI_CreateJavaVM;
    JavaVMInitArgs vm_args;
    JavaVMOption options[1];
    JNIEnv * env;
    
    hLib = LoadLibrary("jvm.dll");
    fct_JNI_CreateJavaVM = (type_JNI_CreateJavaVM)GetProcAddress(hLib, "JNI_CreateJavaVM");
    
    options[0].optionString = "-Djava.class.path=.";
    
    vm_args.options = options;
    vm_args.nOptions = 1;
    vm_args.version = JNI_VERSION_1_4;
    vm_args.ignoreUnrecognized = JNI_FALSE;
    
    return (*fct_JNI_CreateJavaVM)(&jvm, &env, &vm_args);
}
// Compiler settings to your Visual Studio project:
Configuration properties|C/C++|General|Additional Include Directories: {jdk_root_folder}\include\win32;{jdk_root_folder}\include

To run:

Add to the Path environment variable the jvm.dll location
Path=C:\Program Files\Java\jre1.5.0_06\bin\client;%Path%

Regards
843829
thanks :)
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 4 2006
Added on Apr 4 2006
6 comments
381 views