I have a website,my problem is how to run and compile a java program in server side and display the output or error in client side
Asked
Active
Viewed 699 times
-2
-
Are you trying for an online java compiler? – kondu Feb 19 '16 at 05:24
-
what is your problem?can you elaborate more? – soorapadman Feb 19 '16 at 05:27
-
This problem is really big and no one could provide you with a short and simple solution. Also your question lacks a lot of information. Like: Do you already have a server running? Can you already connect it with your client? Do you already know which compiler you want to use? Do you know how to execute applications programmatically? Try to analyze your problem and break it down into smaller problems, for which you can each create a new question on SO – Neuron Feb 19 '16 at 05:28
-
I have install java compiler in server now I need to type a server side program and map it to java compiler and it will run and compile and sent the results to client – madhan ashok Feb 19 '16 at 06:11
-
I am trying for an online compiler – madhan ashok Feb 19 '16 at 06:50
1 Answers
0
Use the code below to run in backend in return response in server side.
Example:
package test;
import javax.tools.*;
public class Test {
public static void main(String[] args) {
String fileToCompile = "C:\\Users\\sanpande\\workspace\\Test\\src\\test" + java.io.File.separator + "MyClass.java";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int compilationResult = compiler.run(null, null, null, fileToCompile);
if (compilationResult == 0) {
System.out.println("Compilation is successful");
} else {
System.out.println("Compilation Failed");
}
}
}
package test;
public class MyClass{
public void myMethod(){
System.out.println("My Method Called");
}
}