JDK 6.0 Java Compiler API setting options

Hello!

in my Webapp I am trying to compile dynamically generated source files with the Compiler API:

JavaCompiler compilerTool = ToolProvider.getSystemJavaCompiler();

StandardJavaFileManager manager = compilerTool.getStandardFileManager(null,null,null);

//directory is the dir with the source files

List<File> fileList = Arrays.asList(directory.listFiles());

Iterable<?extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(fileList);

//set output dir and classpath

List<String> options =new ArrayList<String>();

options.add("-d");

options.add("myAppPath/WEB-INF/classes/");

options.add("-cp");

options.add("myAppPath/WEB_INF/lib/test.jar;myAppPath/WEB_INF/lib/test2.jar");

CompilationTask task = compilerTool.getTask(null, manager, null, options, null, units);

task.call();

manager.close();

because the classes import other classes used in the webapp I have to change the classpath and the output dir should be the classes dir of my webapp. As you can see above I try to set compiler options but that doesn磘 work, I always get:

java.lang.IllegalArgumentException: invalid flag: -d

at com.sun.tools.javac.api.JavacTool.processOptions(JavacTool.java:236)

at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:207)

at com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:53)

I tried the same in a standalone java application and everything worked fine...

maybe anyone got an idea how to set the output and classpath flags right?

[1878 byte] By [_-Mithrandir-_a] at [2007-11-26 15:15:19]
# 1
manager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(new File("myAppPath/WEB-INF/classes/")));
PeterAhea at 2007-7-8 9:07:01 > top of Java-index,Developer Tools,Java Compiler...
# 2

Thank you so much!

after testing a little I found out how to set the classpath with multiple entries on my own.

For others having the same problem:

//set two classpath entries: one dir and one jar

List<File> classPaths = Arrays.asList(new File("myApp/WEB-INF/classes"),

new File("myApp/WEB-INF/lib/classes.jar"));

manager.setLocation(StandardLocation.CLASS_PATH, classPaths);

I am just wondering why it was working in my normal java app with the good in my first post?! Same jdk version, same settings, same same but different :O)

_-Mithrandir-_a at 2007-7-8 9:07:01 > top of Java-index,Developer Tools,Java Compiler...