I'm trying to build the following web functionality :
using javaservlets backed by a tomcat server container I want to build a java web application that given a peice of java code example it should in some way invoke the java compiler and compile the peice of java code reporting any compilation errors..and if compilation is successufull it should display the output of this java code.
Is there a way to invoke the javac compiler from within a servlet ? can I get the output stream from invoking both the javac and java to interpret the code ? should i use any library for dynamically interpreting java code? what are your Ideas for solving this problem ?
thanks for your help indeed.
Joined: Mar 22, 2005
You can use the java.lang.Runtime.exec method to start external proceses (e.g. a "javac" process). That method returns a Process object, through which you can get access to the input, output and error streams of the newly created process. Some basics of Runtime.exec are explained here.
thanks for replying... for the suggestion of dimitter : invoking the javac from exec.RunTime() that require that the jdk should be installed and configured on the machine running the servlet. right ? I'm still looking for any simple solutions. thanks.
Joined: Oct 30, 2001
Well, if you want to compile things, you will need a compiler! There are two main types of approach. You can use the JDK's own compiler. Or you can use another compiler, such as the JDT one mentioned. Which approach is best depends largely on what you can get access to; if you have access to a JDK, then invoking javac is an easy solution.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Hi, when I checked the eclipse JDT compiler i found this peice of code :
which dynamically compiles A.java ; my problem is how i can get the compilation errors -if any- to display them on my web page ? and also how can i know the compilation is successufull from above code ?
I would look at the API. I'm sure there are java-centric ways to communicate with the compiler from your program.
The issues at hand here really aren't servlet specific and I think you're more likely to find people with experience with in process compiling in the Java In General (intermediate) forum. I'll move this thread over there for you.