Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Spawning javac (newbie)
Spawning javac (newbie) [message #160814] Wed, 15 February 2006 16:18 Go to next message
Eclipse UserFriend
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 13:36 Go to previous message
Eclipse UserFriend
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
Previous Topic:1.5M4 - servlet doesn't start
Next Topic:Tutorial Broken?
Goto Forum:
  


Current Time: Thu Apr 25 07:31:23 GMT 2024

Powered by FUDForum. Page generated in 0.03470 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top