1 55 56 package org.apache.bsf.util; 57 58 import java.io.IOException ; 59 import org.apache.bsf.debug.util.DebugLog; 60 61 public class JavaUtils 62 { 63 private static boolean cantLoadCompiler=false; 66 public static boolean JDKcompile(String fileName, String classPath) 67 { 68 DebugLog.stderrPrintln("JavaEngine: Compiling " + fileName, 69 DebugLog.BSF_LOG_L1); 70 DebugLog.stderrPrintln("JavaEngine: Classpath is " + classPath, 71 DebugLog.BSF_LOG_L1); 72 73 String option = (DebugLog.getLogLevel() > 0) ? "-g" : "-O"; 74 75 if(!cantLoadCompiler) 76 { 77 String args[] = { 78 option, 79 "-classpath", 80 classPath, 81 fileName 82 }; 83 try 84 { 85 return new sun.tools.javac.Main(System.err, "javac").compile(args); 86 } 87 catch (Throwable th) 88 { 89 DebugLog.stderrPrintln("WARNING: Unable to load Java 1.3 compiler.", 90 DebugLog.BSF_LOG_L0); 91 DebugLog.stderrPrintln("\tSwitching to command-line invocation.", 92 DebugLog.BSF_LOG_L0); 93 cantLoadCompiler=true; 94 } 95 } 96 97 String args[] = { 99 "javac", 100 option, 101 "-classpath", 102 classPath, 103 fileName 104 }; 105 try 106 { 107 Process p=java.lang.Runtime.getRuntime().exec(args); 108 p.waitFor(); 109 return(p.exitValue()!=0); 110 } 111 catch(IOException e) 112 { 113 DebugLog.stderrPrintln("ERROR: IO exception during exec(javac).", 114 DebugLog.BSF_LOG_L1); 115 } 116 catch(SecurityException e) 117 { 118 DebugLog.stderrPrintln("ERROR: Unable to create subprocess to exec(javac).", 119 DebugLog.BSF_LOG_L1); 120 } 121 catch(InterruptedException e) 122 { 123 DebugLog.stderrPrintln("ERROR: Wait for exec(javac) was interrupted.", 124 DebugLog.BSF_LOG_L1); 125 } 126 return false; 127 } 128 } 129 | Popular Tags |