public int writeWebProgram(WebProgram wp, String webRoot, String classpath) throws Exception { String javaClassesDir = webRoot + File.separator + "WEB-INF" + File.separator + "classes"; JavaProgram jp = wp.getJavaProgram(); int i = this.writeAndCompileJavaProgram(jp, javaClassesDir, classpath); for (Iterator itr = wp.getASPs().iterator(); itr.hasNext(); ) { ASP asp = (ASP) itr.next(); String aspFilename = Util.replaceString(asp.getName(), "aspx", "jsp"); FileOutputStream fos = new FileOutputStream(new File(webRoot, aspFilename)); asp.write(fos); // asp.write(System.out); } return i; }
public int compileJavaProgram(JavaProgram jp, String writeDirectory, String classpath) throws Exception { if (!jp.isTypeResolved()) { System.out.println( "Compilation will not take place since there were type resolution errors."); return -1; } String fileList = jp.getFilesAsString(); String command = "javac -d " + writeDirectory + " -classpath " + classpath + " " + fileList; // System.out.println(command); System.out.print("Compiling..."); Process p = Runtime.getRuntime().exec(command); // need to squirt the output into the InputStream is = p.getErrorStream(); Util.read(is, "compiler"); // blocks here int exitValue = p.exitValue(); return exitValue; }