|
-
Jul 2nd, 2008, 04:02 PM
#1
Thread Starter
Frenzied Member
[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.
-
Jul 2nd, 2008, 04:32 PM
#2
Re: problem with java runtime compilation in my jsp file
I'm not a JSP expert but I think you need to add the import tag to your code
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 2nd, 2008, 04:47 PM
#3
Thread Starter
Frenzied Member
Re: problem with java runtime compilation in my jsp file
Yes ive got this at the top of the jsp
Code:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*,java.io.*,java.sql.*,java.io.File" %>
it just doesnt compile the file over the web. any other way it compiles fine.
if i remove the 'implemets ComputerPlayerInterface' from the TestPlayer.java then it compiles fine over the web...
-
Jul 2nd, 2008, 05:16 PM
#4
Re: problem with java runtime compilation in my jsp file
try moving ComputerPlayerInterface to a package then import it in your jsp file
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 3rd, 2008, 01:54 AM
#5
Thread Starter
Frenzied Member
Re: problem with java runtime compilation in my jsp file
Ok i now did the package stuff, ComputerPlayerInterface.java is in a folder called ACS
Code:
package ACS;
public interface ComputerPlayerInterface {
// Method signatures, which all submitted computer players must have.
String test();
}
now on my test.jsp page: I did the necessary import
Code:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*,java.io.*,java.sql.*,java.io.File,ACS.ComputerPlayerInterface.*;" %>
<%
// 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 -classpath \"ComputerPlayerInterface\" \"" + 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) { }
%>
when i open the page i still have the same problem, it doesnt seem to compile:
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
it just can't seem to find the ComputerPlayerInterface for some reason
Last edited by Pouncer; Jul 3rd, 2008 at 02:10 AM.
-
Jul 3rd, 2008, 02:18 AM
#6
Re: problem with java runtime compilation in my jsp file
Code:
package myPackage;
public interface ComputerPlayerInterface {
// Method signatures, which all submitted computer players must have.
String test();
}
dude, that's java 101
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 3rd, 2008, 06:25 AM
#7
Thread Starter
Frenzied Member
Re: problem with java runtime compilation in my jsp file
tried the package stuff, didnt work. im trying to navigate to the directory first then doing the javac command:
Code:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*,java.io.*,java.sql.*,java.io.File" %>
<%
// Attempt to automatically compile a file.
String s = null;
String dir = "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\eg\\submissions\\msk9";
try {
Process p = Runtime.getRuntime().exec("cd \"" + dir + "\" : javac \"TestPlayer.java\"");
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 (Exception e) { out.println(e.toString()); }
%>
but its giving me an exception error
java.io.IOException: CreateProcess: cd "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\eg\submissions\msk9" : javac "TestPlayer.java" error=2
even when i put this in my cmd window:
cd "C:\Program Files\Apache Software Foundation\
Tomcat 6.0\webapps\eg\submissions\msk9" : javac "TestPlayer.java"
The system cannot find the path specified.
Last edited by Pouncer; Jul 3rd, 2008 at 06:28 AM.
-
Jul 3rd, 2008, 06:54 AM
#8
Re: problem with java runtime compilation in my jsp file
Java is a programming language not a shell script
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 3rd, 2008, 08:00 AM
#9
Thread Starter
Frenzied Member
Re: problem with java runtime compilation in my jsp file
i found a way to execute 2 commands in 1 go via the &&. e.g:
cd "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\eg\submiss
ions\msk9" && javac "TestPlayer.java"
that works when i typed it in my cmd window.
but my code below in my jsp file:
Code:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.util.*,java.io.*,java.sql.*,java.io.File" %>
<%
// Attempt to automatically compile a file.
String s = null;
String dir = "C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\webapps\\eg\\submissions\\msk9";
try {
Process p = Runtime.getRuntime().exec("cd \"" + dir + "\" && javac \"TestPlayer.java\"");
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 (Exception e) { out.println(e.toString()); }
%>
when i run the jsp file in my browser, it gives me an error:
java.io.IOException: CreateProcess: cd "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\eg\submissions\msk9" && javac "TestPlayer.java" error=2
Last edited by Pouncer; Jul 3rd, 2008 at 08:13 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|