Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4149295

New JVM options setting structure - classpath ignored

XMLWordPrintable

    • 1.2beta4
    • x86, sparc
    • solaris_2.5.1, windows_nt
    • Not verified



      Name: rm29839 Date: 06/16/98


      I've tried to use mechanism of setting JVM
      options, introduced with JDK1.2. Unfortunately,
      it looks like "classpath" option is ignored.

      Below is source code. JDK1.1 options setting
      affects classpath, while JDK1.2 does not.

      #ifdef JDK1_2
        {
          JavaVMOption options[2];

          options[0].name = "classpath";
          options[0].value.p = ".;c:\\jdk1.2beta3\\lib\\classes.zip";
          
          options[1].name = "verbose";
          options[1].value.p = "class";
          
          vm_args.version = 0x00010002;
          vm_args.options = options;
          vm_args.nOptions = sizeof(options)/sizeof(options[0]);
          vm_args.result = NULL;
          
          res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
        }
      #else


        vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
        /* Get the default initialization arguments and set the class
         * path */

        JNI_GetDefaultJavaVMInitArgs(&vm_args);

        newClassPath = (char *)malloc(strlen(vm_args.classpath)+strlen(".;")+1);
        strcpy(newClassPath,".;");
        strcat(newClassPath,vm_args.classpath);
        vm_args.classpath = newClassPath;


        
        /* load and initialize a Java VM, return a JNI interface
         * pointer in env */
        res = JNI_CreateJavaVM(&jvm, (void **)&env, &vm_args);
      #endif


         No, my problem appears to be different: I don't use native code at all. Instead,
      I'm going to integrate Java in application, using JNI invocation interface. As part
      of the effort, I would like to enable the application developer to alter/extend JVM
      classpath. With JDK1.1 JVM initialization, the code looks like:

        vm_args.version = 0x00010001; /* New in 1.1.2: VM version */
      /* Get the default initialization arguments and set the class
       * path */
        JNI_GetDefaultJavaVMInitArgs(&vm_args);
        newClassPath = (char *)malloc(strlen(vm_args.classpath)+strlen(".;")+1);
        strcpy(newClassPath,".;");
        strcat(newClassPath,vm_args.classpath);
        vm_args.classpath = newClassPath;
        res = JNI_CreateJavaVM(&jvm, &env, &vm_args);

        cls = env->FindClass(env,"MyClass");/*MyClass.class is located in current directory*/



         JVM, created by the code takes into account new class path. I failed to implement
      classpath manipulation using new JVM creation API, intorduced in JDK1.2. Acoording
      to documentation, coming with JDK 1.2beta, initialization should look like:


          JavaVMOption options[2];
          options[0].name = "classpath";
          options[0].value.p = ".;c:\\jdk1.2beta3\\lib\\classes.zip";

          options[1].name = "verbose";
          options[1].value.p = "class";

          vm_args.version = 0x00010002;
          vm_args.options = options;

          vm_args.nOptions = sizeof(options)/sizeof(options[0]);
          vm_args.result = NULL;

          res = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args);
          cls = env->FindClass(env,"MyClass");/*MyClass.class is located in current directory*/

           The problem manifests itself by failure to load "MyClass" from the current
      directory. The "verbose" keyword has an effect, so the problem is related to
      "classpath" keyword treatment. BTW, the new API loses the ability to modify
      classpath. With JDK 1.1, it is possible to query default JVM classpath and add
      directory, with JDK 1.2, classpath can be only set.
          Access to JDK 1.2 source code would help to locate the bug ( or clear
      misunderstaning - it is entirely possible that sample code or documentation is
      inconsistent with the implementation ). Is it possible to get JDK 1.2 sources?
      (Review ID: 33052)
      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: