Results 1 to 9 of 9

Thread: [RESOLVED] problem with java runtime compilation in my jsp file

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Resolved [RESOLVED] problem with java runtime compilation in my jsp file

    I've embedded this java code in my test.jsp file (it attempts to compile a file at runtime)

    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 when i browse to my test.jsp on the web, the page gives me:

    Your 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
    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 error

    This is TestPlayer.java

    Code:
    import java.io.*;
    
    public class TestPlayer implements ComputerPlayerInterface {
    
        public String test() {
    	return "Tom";
        }
    }
    This is ComputerPlayerInterface.java
    Code:
    public interface ComputerPlayerInterface {
        
        // Method signatures, which all submitted computer players must have.
        String test();
    }
    Both files are in this folder;
    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
    Last edited by Pouncer; Jul 2nd, 2008 at 04:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width