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);
上面运行正常时,因为用于编译所需的所有jars
作为JUnit测试执行abc.java
文件。但是当相同的代码作为服务器运行时,它无法找到所需的jar
文件。 System.getProperty("java.class.path")
的输出是 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
System.getProperty(“java.class.path”)不显示“WEB-INF/LIB”和包括罐子
所以,我的问题是如何让编译器引用从WEB-INF/lib目录中的jar文件?
你是如何在应用程序中打包(生成WAR)的? – CoolBeans 2010-11-25 01:43:07