• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling through Servlet

 
Revati Pathak
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could u give complete code ???
try changing the name Try.java to something other...
might be try is an keyword...
guessing.
Bhupendra
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic