A
Andrew Thompson
I am developing a tool to comprehensively check and
analyse JWS launch files. After well-formedness and
validation, and checking a slew of other aspects of
the launch files, the last check I want to offer is
the acid test, the result of a launch.
Unfortunately, when I attempt* to capture the output
of a javaws Process started by the app., it returns
no data at all, and the exit code is always '0'.
Questions:
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.
2) Is the lack of output a problem in the code used, or
is javaws simply not dumping anything useful to the output?
(Expermiments from the command line suggest the latter,
but I felt it worth checking).
3) Are there any options I missed, to get javaws to be
more verbose about the launch?
4) Are there any better strategies to achieve the feature?
(A 'management' type API that allows me to access individual
launch exceptions would be ideal.) Note: Neither jdb nor
jconsole seems to be the answer (as far as I can determine).
* Here is a short code that should demonstrate the
failure..
<sscce>
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
class TestJavawsOutput {
public static void main(String[] args)
throws IOException {
ProcessBuilder pb = new ProcessBuilder(
"javaws",
// pops a dialog before launching the app.
//"-verbose",
"-wait",
"-J",
"-Xprof",
// a 'dud' JNLP file
"http://no.com/missing.jnlp");
// combine the output and error streams
pb = pb.redirectErrorStream(true);
Process p = pb.start();
InputStream is = p.getInputStream();
ByteArrayOutputStream launchResult =
new ByteArrayOutputStream();
byte[] b = new byte[1024];
int read = is.read(b);
while ( read>-1 ) {
launchResult.write(b,0,read);
read = is.read(b);
}
try {
int processResult = p.waitFor();
System.out.println(
"Exit code: " + processResult);
launchResult.flush();
System.out.println(
"'" + launchResult.toString() + "'");
} catch(InterruptedException ie) {
ie.printStackTrace();
}
}
}
</sscce>
Typical output:
From the dialogs that javaws shows the user..
<on-screen>
CouldNotLoadArgumentException[
Could not load file/URL specified:
http://no.com/missing.jnlp]
at com.sun.javaws.Main.launchApp(Unknown Source)
<on-screen>
From the command line
<cli>
Exit code: 0
''
Press any key to continue . . .
</cli>
analyse JWS launch files. After well-formedness and
validation, and checking a slew of other aspects of
the launch files, the last check I want to offer is
the acid test, the result of a launch.
Unfortunately, when I attempt* to capture the output
of a javaws Process started by the app., it returns
no data at all, and the exit code is always '0'.
Questions:
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.
2) Is the lack of output a problem in the code used, or
is javaws simply not dumping anything useful to the output?
(Expermiments from the command line suggest the latter,
but I felt it worth checking).
3) Are there any options I missed, to get javaws to be
more verbose about the launch?
4) Are there any better strategies to achieve the feature?
(A 'management' type API that allows me to access individual
launch exceptions would be ideal.) Note: Neither jdb nor
jconsole seems to be the answer (as far as I can determine).
* Here is a short code that should demonstrate the
failure..
<sscce>
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
class TestJavawsOutput {
public static void main(String[] args)
throws IOException {
ProcessBuilder pb = new ProcessBuilder(
"javaws",
// pops a dialog before launching the app.
//"-verbose",
"-wait",
"-J",
"-Xprof",
// a 'dud' JNLP file
"http://no.com/missing.jnlp");
// combine the output and error streams
pb = pb.redirectErrorStream(true);
Process p = pb.start();
InputStream is = p.getInputStream();
ByteArrayOutputStream launchResult =
new ByteArrayOutputStream();
byte[] b = new byte[1024];
int read = is.read(b);
while ( read>-1 ) {
launchResult.write(b,0,read);
read = is.read(b);
}
try {
int processResult = p.waitFor();
System.out.println(
"Exit code: " + processResult);
launchResult.flush();
System.out.println(
"'" + launchResult.toString() + "'");
} catch(InterruptedException ie) {
ie.printStackTrace();
}
}
}
</sscce>
Typical output:
From the dialogs that javaws shows the user..
<on-screen>
CouldNotLoadArgumentException[
Could not load file/URL specified:
http://no.com/missing.jnlp]
at com.sun.javaws.Main.launchApp(Unknown Source)
<on-screen>
From the command line
<cli>
Exit code: 0
''
Press any key to continue . . .
</cli>