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

JSR 199: StandardFileManager: cannot set CLASS_PATH location

    Details

    • Subcomponent:
    • Resolved In Build:
      b85
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      The class path for the compiler cannot be set by StandartFileManager.setLocation(CLASS_PATH, ...) method. I reproduce the failure under JDK b82. Please see an example below:
      ===Compiler.java===
      import java.util.Collections;
      import javax.tools.JavaCompilerTool;
      import static javax.tools.JavaCompilerTool.*;
      import javax.tools.JavaFileObject;
      import javax.tools.StandardJavaFileManager;
      import javax.tools.StandardJavaFileManager.StandardLocation;
      import javax.tools.ToolProvider;

      public class Compiler {
          
          public static void main(String[] argv) {
           JavaCompilerTool compiler =
           ToolProvider.getSystemJavaCompilerTool();
              StandardJavaFileManager fileManager =
           compiler.getStandardFileManager(null);
              fileManager.setLocation(StandardLocation.CLASS_PATH,
                     Collections.singleton(
           new File("classes/")));
              Iterable<? extends JavaFileObject> compilationUnits =
                     fileManager.getJavaFileObjectsFromStrings(
           Collections.singleton("B.java"));
              compiler.getTask(null, fileManager, null, null, null,
           compilationUnits).run();
          
          }
      }
      ====
      ====B.java (in the same directory as Compiler.java===
      public class B { { new A(); } }
      ====
      ====A.java (in the 'classes' directory===
      public class A {}
      ====
      ====run.sh===
      JDK=/java/re/jdk/6.0/latest/binaries/solaris-sparc
      echo Compile Compiler.java...
      $JDK/bin/javac Compiler.java
      echo Invoke Compiler...
      $JDK/bin/java Compiler
      echo Set classpath externally and invoke compiler again...
      $JDK/bin/java -cp classes:. Compiler
      ====
      Results:
      ---
      ag153348@oink$ . run.sh
      Compile Compiler.java...
      Invoke Compiler...
      B.java:1: cannot find symbol
      symbol : class A
      location: class B
      public class B { { new A(); } }
                              ^
      1 error
      Set classpath externally and invoke compiler again...
      ag153348@oink$
      ---
      It seems that the class path passed to the JavaCompilerTool via option "-cp" works fine. Currently, we use this way as a workaround.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                agavrilosunw Alexey Gavrilov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: