Search code examples
javaantcompilationclassloaderjavac

how to compile java code setting classloader (via ant task)


I need to set the classloader of javac of my task ant which compiles my code.. i ve read this stackoverflow post but this

javac -J-Djava.system.class.loader=org.awesome.classloader sourcefile.java

didnt worked for me, always returning class not found exception.. and, yes, i set the classpath for the source code and the compiled classloader .class


Solution

  • After some study of this task I found a way. I initialized a custom classloader and then I used it through the new Compiler API from Java 6

    http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html