public ClassLoader compile(File dir) {
EclipseJavaCompilerSettings settings = new EclipseJavaCompilerSettings();
Map<Object, Object> map = settings.getMap();
map.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
EclipseJavaCompiler compiler = new EclipseJavaCompiler(settings);
if (!dir.exists()) {
throw new BuildException("Compilation directory does not exist!");
}
FileResourceReader reader = new FileResourceReader(dir);
List<String> classes = new ArrayList<String>();
for (String s : reader.list()) {
String name = AbstractJavaCompiler.convertResourceNameToClassName(s);
name = name.replace('/', '.');
name = name.replace('\\', '.');
classes.add(name);
}
MemoryResourceStore store = new MemoryResourceStore();
CompilationResult result
= compiler.compile(classes.toArray(new String[classes.size()]), reader, store);
CompilationProblem[] errors = result.getErrors();
for (CompilationProblem p : errors) {
System.out.println(p.getMessage());
}