File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compiling through Servlet" Watch "Compiling through Servlet" New topic
Author

Compiling through Servlet

Revati Pathak
Greenhorn

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 Try.java .
Interface CommonInterface.java
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 Rule5.java) is also in the same folder.
In Try.java , i have written a code to compile a file Rule5.java
Runtime rn = Runtime.getRuntime();
Process process =
rn.exec("javac -classpath c:\\JavaWebServer2.0\\servlets\\
c:\\JavaWebServer2.0\\servlets\\rulebasedvalidations\\"+className);
where className is Rule5.java
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.
-Pragati

Mahajan Bhupendra
Ranch Hand

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


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

Joined: Mar 22, 2000
Posts: 12821
    
    5
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.
Bill
Revati Pathak
Greenhorn

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.
Regards,
-Pragati
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling through Servlet