Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDK 6.0 Java Compiler API setting options

843810Jan 16 2007 — edited May 13 2008
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�t 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2008
Added on Jan 16 2007
4 comments
367 views