Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Online Compiler

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 66215
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!