I've embedded this java code in my test.jsp file (it attempts to compile a file at runtime)
Now when i browse to my test.jsp on the web, the page gives me:Code:<% // Attempt to automatically compile a file. String s = null; String dir = "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\eg\\submissions\\msk9\\"; String f = dir + "TestPlayer.java"; try { Process p = Runtime.getRuntime().exec("javac \"" + f + "\""); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); ArrayList array = new ArrayList(); while ((s = stdError.readLine()) != null) { array.add(s); } if (array.size() > 0) { out.println("Your submission had compilation errors:<br><br>"); for (int i = 0; i < array.size(); i++) { out.println(array.get(i) + "<br>"); } } else { out.println("Your submission successfully compiled and has been accepted by the system."); } } catch (IOException e) { } %>
Now this is a problem, it should compile fine.. it compiles absolutely fine when i execute the normal javac command in the cmd window. but this doesnt seem to work on the web jsp. the ComputerPlayerInterface,java is also in the same directory so i dont know why it throws that errorYour submission had compilation errors:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\eg\submissions\msk9\TestPlayer.java:3: cannot find symbol
symbol: class ComputerPlayerInterface
public class TestPlayer implements ComputerPlayerInterface {
^
1 error
This is TestPlayer.java
This is ComputerPlayerInterface.javaCode:import java.io.*; public class TestPlayer implements ComputerPlayerInterface { public String test() { return "Tom"; } }
Both files are in this folder;Code:public interface ComputerPlayerInterface { // Method signatures, which all submitted computer players must have. String test(); }
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\eg\submissions\msk9
i dont know why the runtime code doesnt compile on the web




Reply With Quote