JavaCompilerTool.setClassPath() clears classpath in JavaCompilerTool.setOption("-classpath")
Tried in Solaris SunOS 5.10 Generic sun4u sparc SUNW,Ultra-60
<java-version>
bash-3.00$ java -version
java version "1.6.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-beta-b59a)
Java HotSpot(TM) Client VM (build 1.6.0-beta-b59a, mixed mode)
</java-version>
To re-produce the problem :
1) keep Foo.java,JavacOptionsTest02.java in the same directory.
2) Create one directory with the name "Pack1" in the directory where Foo.java is kept
3) Keep Bar1.java in Pack1
4) Create one directory with the name "Pack2" in the directory where Foo.java is kept
5) Keep Bar2.java in Pack2
6) Run JavacOptionTest02.
Testcases:
<JavacOptionsTest02.java>
import java.io.File;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.tools.*;
public class JavacOptionsTest02 {
public static void main(String... arg) throws Exception {
JavaCompilerTool javac = ToolProvider.defaultJavaCompiler();
JavaFileManager jfm = javac.getStandardFileManager();
javac.setOption("-classpath","Pack1");
List<File> cpFiles= new ArrayList<File>();
//cpFiles.add(new File("Pack1"));
cpFiles.add(new File("Pack2"));
javac.setClassPath(cpFiles);
JavaFileObject jfo = jfm.getFileForInput("Foo.java");
Iterable<DiagnosticMessage> iteDM =
javac.run((PrintWriter)null, jfo).getDiagnostics();
for(DiagnosticMessage message : iteDM)
System.out.println("\nMessage : "+message.toString());
}
}
</JavacOptionsTest02.java>
<Foo.java>
public class Foo {
public static void main(String[] args) {
Bar1 bar1 = new Bar1();
Bar2 bar2 = new Bar2();
}
}
</Foo.java>
<Bar1>
public class Bar1 {
}
</Bar1>
<Bar2>
public class Bar2 {
}
</Bar2>
Output of the code when JavacOptionsTest02 is run
<Output>
bash-3.00$ java JavacOptionsTest02
Message : foo.java:3: cannot find symbol
symbol : class Bar1
location: class foo
Message : foo.java:3: cannot find symbol
symbol : class Bar1
location: class foo
</Output>
If uncomment the line "//cpFiles.add(new File("Pack1"));" Then this will work fine
OR
Change the line javac.setOption("-classpath","Pack1") to javac.setOption("-classpath","Pack1","Pack2"); and remove the code javac.setClassPath(..);