wood burning stoves 2.0*
The moose likes Java in General and the fly likes Online Compiler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Online Compiler" Watch "Online Compiler" New topic
Author

Online Compiler

T. N.V.Pandian
Greenhorn

Joined: Nov 09, 2008
Posts: 2
Hi Friends,
I need to develop a webapplication (Online Java Compiler) ,which gets .java file as input and compiles it and then run it.The output as well as error messages(which normally we got in the console) should be dispalyed in the browser.

I have used the following code snippet in my JSP.


It compiles the java file and produces the class file.The problem is,in case of any errors(compilation or runtime),i didn't get any error meassages in the browser.Also,i am not sure how to display the output to the browser.

Please help me to display the error messages as well as the output to the browser window.

Thanks in Advance.
TNVP


T.N.V.Pandian,
TamilNadu,
India.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41613
    
  55
In Java 6 you can use the javax.tools.JavaCompiler class to drive the compiler from within Java code, and get at its output.

You should use a very strict SecurityManager to execute the code, lest it interferes with the server, unintentionally or otherwise.


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38497
    
  23
And there is a lot more to Runtime.exec() than that. Look for the article entitled "when Runtime.exec() won't" on a Google search.
jack wenttohill
Greenhorn

Joined: Apr 26, 2009
Posts: 9
Its easy to do but difficult to maintain.

one applet handler
http://www.innovation.ch/java/java_compile.html

When you develop just think of a simple scenario:

Some body likes to compile and run a java file with infinity loop.
Or inside it using some Runtime.exec('System critical command'), how you are going to handle them.

Thanks
Jack


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Online Compiler