Two Laptop Bag
The moose likes Servlets and the fly likes Compiling through Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compiling through Servlet" Watch "Compiling through Servlet" New topic

Compiling through Servlet

Revati Pathak

Joined: Feb 19, 2001
Posts: 26
Hi Friends,
I have wrriten a servlet. the basic purpose of this servlet is that, it will capture some info from HTML Page, then it will create one java class (physical file). then it will compile the file . and then it will call the method of that class.
I am using JavaWebServer2.0
My servlet is .
the java class that i am generating runtime is implementing CommonInterface.
All files are in package rulebasedvalidations.
Now, all my class files(Try.class,CommonInterface.class )are in c:\JavaWebServer2.0\servlets\rulebasedvalidations
my new source file(suppose named is also in the same folder.
In , i have written a code to compile a file
Runtime rn = Runtime.getRuntime();
Process process =
rn.exec("javac -classpath c:\\JavaWebServer2.0\\servlets\\
where className is
but here i am getting an error like Superclass java.lang.Object of rulebasedvalidations.Rule5 not found.
when i tried the same command from DOS prompt c:\> its working perfectly fine.

Could any one please help me to solve this problem?
thanking in advance.

Mahajan Bhupendra
Ranch Hand

Joined: Dec 01, 2000
Posts: 118
could u give complete code ???
try changing the name to something other...
might be try is an keyword...

<B>Bhupendra Mahajan</B>
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
I suspect what is happening is that when you do an exec from Java, the executed program does NOT get the normal set of Environment variables, but a reduced set. Therefore javac is NOT finding any of the standard libraries.
You could use one of the exec variants in which you can set up environment variables and include CLASSPATH information, or you could add classpath for the standard library to the command line.
I find it a lot easier to use the exec version which takes arrays of String rather than a single great long String that has to be parsed.
Revati Pathak

Joined: Feb 19, 2001
Posts: 26
Hello Friends,
Thanks for your reply.
My problem has been solved. actually in exec command i gave the whole path of jdk1.3/bin/javac. Now it is working.
I agree. Here's the link:
subject: Compiling through Servlet
It's not a secret anymore!