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 works fine when executed as a JUnit test, since all jars needed to compile the abc.java file. But when the same code runs as a server, it cannot 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 to get the compiler to reference jar files from the WEB-INF / lib directory?
source share