Spawning javac (newbie) [message #160814] |
Wed, 15 February 2006 11:18  |
Eclipse User |
|
|
|
Originally posted by: Ben_Engbers.yahoo.com
Hello,
I am trying to write a webservice which generates a .java file, compiles
it to a .class, loads it into a Byte [] and returns the Byte []. (I use
wtp-all-in-one-sdk-1.0-win32.zip and jdk1.5.0_06)
If I try to return a dummy .class, the service works. However if I try
to spawn the javac compilation, WTP keeps on waiting on the line
p.waitfor() (See code below). However if I deploy the service on Tomcat,
it shows this message:
java.io.IOException: CreateProcess: javac Djava.ext.dirs=WEB-INF\lib
minlnv\pdf\<fileName>.java error=2
I have googled a lot and tried several solutions, but the compilation
still doesn't start. I use the following code:
String [] command = {"javac", "Djava.ext.dirs=WEB-INF"
+File.separator+ "lib",
"-classpath \"C:" +File.separator + "Program Files" + File.separator+
"Java" +File.separator+ "jdk1.5.0_06\"",
"-d ." + File.separator +".",
"minlnv" + File.separator +"pdf" + File.separator + srcStub};
Process p = Runtime.getRuntime().exec(command);
try {
p.waitFor();
System.out.println("outPut - " + p.exitValue());
} catch (InterruptedException e) {
System.out.println(e.getMessage());
int ret = p.exitValue();
System.out.println("outPut ret = " + ret);
e.printStackTrace();
}
I have added javac to the PATH-setting.
Can anybody help me?
Ben
|
|
|
Re: Spawning javac (newbie) [message #160990 is a reply to message #160814] |
Thu, 16 February 2006 08:36  |
Eclipse User |
|
|
|
Originally posted by: wknauf_NO_._INSIDE_hg-online.de
Hi Ben,
I think the problem is that the JavaC process generates some output, and this
output is buffered and the process blocks when the buffer is full. So you have
to read from this buffer constantly.
In one of our apps these lines of code worked (replacing your "p.waitFor()") :
Process process = runtime.exec( new String [] {statementArray}, null);
InputStream ip = process.getInputStream();
InputStream ep = process.getErrorStream();
//Wait for process end, read stdout and stderr constantly:
String strErrorStreamRead = "";
String strInputStreamRead = "";
int intByteErrorStreamNext = -1;
int intByteInputStreamNext = -1;
while ( (intByteErrorStreamNext = ep.read() ) != -1 ||
(intByteInputStreamNext = ip.read() ) != -1)
{
//System.out.print ( (char) intByteErrorStreamNext);
if (intByteErrorStreamNext != -1)
strErrorStreamRead += (char) intByteErrorStreamNext;
if (intByteInputStreamNext != -1)
strInputStreamRead += (char) intByteInputStreamNext;
}
process.waitFor();
Hope this helps
BTW: I would suggest you split your parameter string to a string array: at each
INTENDED space starts a new parameter. Spaces in file paths remain the same. I
had some nasty problems with spaces in a path, because this made multiple
parameters. I think quotes will not always work.
Wolfgang
Ben Engbers wrote:
> Hello,
>
> I am trying to write a webservice which generates a .java file, compiles
> it to a .class, loads it into a Byte [] and returns the Byte []. (I use
> wtp-all-in-one-sdk-1.0-win32.zip and jdk1.5.0_06)
> If I try to return a dummy .class, the service works. However if I try
> to spawn the javac compilation, WTP keeps on waiting on the line
> p.waitfor() (See code below). However if I deploy the service on Tomcat,
> it shows this message:
>
> java.io.IOException: CreateProcess: javac Djava.ext.dirs=WEB-INF\lib
> minlnv\pdf\<fileName>.java error=2
>
> I have googled a lot and tried several solutions, but the compilation
> still doesn't start. I use the following code:
>
> String [] command = {"javac", "Djava.ext.dirs=WEB-INF"
> +File.separator+ "lib",
> "-classpath \"C:" +File.separator + "Program Files" +
> File.separator+ "Java" +File.separator+ "jdk1.5.0_06\"",
> "-d ." + File.separator +".",
> "minlnv" + File.separator +"pdf" + File.separator + srcStub};
>
> Process p = Runtime.getRuntime().exec(command);
> try {
> p.waitFor();
> System.out.println("outPut - " + p.exitValue());
> } catch (InterruptedException e) {
> System.out.println(e.getMessage());
> int ret = p.exitValue();
> System.out.println("outPut ret = " + ret);
> e.printStackTrace();
> }
>
> I have added javac to the PATH-setting.
> Can anybody help me?
>
> Ben
|
|
|
Powered by
FUDForum. Page generated in 0.03991 seconds