Re: Correct way to load jvm.dll in a JNI application?



Currently I'm querying the Windows registry like this:
- read value at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime
Environment\CurrentVersion;
- read value HKEY_LOCAL_MACHINE\SOFTWARE\\JavaSoft\\Java Runtime
Environment\<CurrentVersion>\RuntimeLib

I don't think java is required to put anything in the registry. Also there may be installed JDK without JRE and the key in registry may be different (it is different with Sun's JVM). The may be also several different JVMs in the registry.
Trying to guess correct JVM location is a good idea but you should consider to let end user configure the location.

Then I put jvm.dll's folder in front of process' PATH environment
variable and then execute:

JavaVM *vm=NULL;
JNIEnv* java_env=NULL;
JavaVMInitArgs vm_args={0};
vm_args.version = JNI_VERSION_1_6;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
// assignment of vm_args.options skipped...
JNI_CreateJavaVM(&vm, (void **)&java_env, &vm_args)) ;

Try loading java library dynamically (on windows start with LoadLibrary() function) - this way you won't have to link your application with jvm.lib and in case of any error you can handle it in the application (default windows behaviour is to show message box and stop loading application).
.



Relevant Pages

  • Re: Cannot uninstall previous versions of Java 2
    ... the registry makes me a little nervous. ... I also have the current JVM now installed and hope ... When I try to uninstall various components of JAVA 2 v 1.4.2_0x, ... - java.pnf from the \%systemroot%\inf folder ...
    (microsoft.public.windowsxp.general)
  • Re: Correct way to load jvm.dll in a JNI application?
    ... I don't think java is required to put anything in the registry. ... the application (default windows behaviour is to show message box and ... stop loading application). ...
    (comp.lang.java.programmer)
  • Re: 5th time asking....
    ... >Because of the conflict between Sun and MS, the Java VM ... >> I have a brand new computer with a fresh install of Win ... Set your system to western european (windows) ... >> related to a corruption in the registry. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Internet Explorer Java Failure
    ... checker in C that just looked at all the registry entries for Java, ... to keep, and hook them up, and get rid any dangling references. ... The only sure way is to format the disk and start over. ...
    (comp.lang.java.programmer)
  • Re: iexplore.exe error when I try to execute Java
    ... Internet Explorer has encountered a problem and needs to close. ... ensure your registry is clean ... uninstall java then reboot. ... Java website to test the installation, I get a Internet Explorer 'needs ...
    (microsoft.public.windowsxp.general)