String CompilePath = "abc.java";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String classpath = System.getProperty("java.class.path");
System.setProperty("java.class.path", classpath + ";" + LocalMachine.home + "WebContent/WEB-INF/lib");
int result = compiler.run(null, null, null, CompilePath);
The above runs fine when executed as a JUnit test since all the jars
required for compiling the abc.java
file. But when the same code is being run in as server, it fails to find the required jar
files. The output of System.getProperty("java.class.path")
is
E:\apache-tomcat-7.0.4\bin\bootstrap.jar;E:\apache-tomcat-7.0.4\bin\tomcat-juli.jar;C:\Program Files\Java\jdk1.6.0_21\lib\tools.jar
So, my question is how do I make the compiler refer to the jar files from the WEB-INF/lib directory?