Java 6 JavaCompiler PropertyPermission problem
Hi
I am using the new javax.tools functionalities to compile on the fly java code. This works fine when run as standalone application, but I get an exception when I try to run through web start. The error I get is the following:
error: Could not createclass loaderfor annotation processors: access denied (java.util.PropertyPermission java.endorsed.dirs read)
In the jnlp I have specified the <security><all-permissions/></security> part (and in fact other parts which do require privileges do work fine!). I also do a small test in the code:
java.util.PropertyPermission perm =new java.util.PropertyPermission("java.endorsed.dirs","read");
System.getSecurityManager().checkPermission(perm);
and this does not generate an exception.
I have also tried to run the code in a doPrivileged section... no result.
The full source code looks like this:
java.util.PropertyPermission perm =new java.util.PropertyPermission("java.endorsed.dirs","read");
System.getSecurityManager().checkPermission(perm);
final Map<String, JavaFileObject> output =
new HashMap<String, JavaFileObject>();
final JavaCompiler compiler =
ToolProvider.getSystemJavaCompiler();
final DiagnosticCollector<JavaFileObject> diagnostics =
new DiagnosticCollector<JavaFileObject>();
final JavaFileManager jfm =new
ForwardingJavaFileManager<StandardJavaFileManager> (
compiler.getStandardFileManager(diagnostics, Locale.getDefault(), Charset.defaultCharset())){
@Override
public JavaFileObject getJavaFileForOutput(Location location,
String name,
Kind kind,
FileObject sibling)throws IOException{
JavaFileObject jfo =new RAMJavaFileObject(name, kind);
output.put(name, jfo);
return jfo;
}
};
final List<JavaFileObject> files =new ArrayList<JavaFileObject>();
for ( FileSpec fs : fileSpecs )
files.add(generateJavaSource(fs.getFileName(), fs.getSource()));
CompilationTask task = compiler.getTask(
null, jfm, diagnostics, null, null,
files);
if (! task.call()){
for(Diagnostic dm : diagnostics.getDiagnostics())
System.err.println(dm);
thrownew RuntimeException("Could not compile");
}
(some parts are omitted)
Can anybody help?
Thanks,
Vito Impagliazzo

