running Jar file in back end of webserver

S

shabbir_a

Hi,

is there anyone who can help with this problem. I have a piece of
java software that is sitting on my webserver. I can run the jar
file from within the command line and it returns a series of results
to the command line. I also have the source code for this app.

What I want to know, is from within a webapp, can I access this java
app, send it some variables and then pickup what it usually outputs?

If I can, how?

Thanks in advance.
 
K

Kai Schwebke

is there anyone who can help with this problem. I have a piece of
java software that is sitting on my webserver. I can run the jar
file from within the command line and it returns a series of results
to the command line. I also have the source code for this app.

What I want to know, is from within a webapp, can I access this java
app, send it some variables and then pickup what it usually outputs?

If I can, how?

It may be easier to use the classes of this app directly instead of
using the entire app as "black box".

If not, you may use this code to embedd a java console app:


// redirect standard output
java.io.ByteArrayOutputStream captureOut =
new java.io.ByteArrayOutputStream();

// flush system out and bind to capture buffer
PrintStream oOut = System.out;
PrintStream nOut = new PrintStream(captureOut);
oOut.flush();
System.setOut(nOut);

// call java app's main method
my.little.java.command.line.app.Main(/* arguments as String[] */)

// close capture buffer, reassign original system out
nOut.close();
System.setOut(oOut);

// write captured bytes (optional)
oOut.write(captureOut.toByteArray());

// captureOut.toString() == output of main


You may catch to much output, if other threads write to System.out
as well. Normally a web app should not do this, but use a logging
facility instead.


Kai
 
S

shabbir_a

Thanks for the info Kai. You mentioned I can call the class
directly - I am new to java, so am not sure how to do this - can I
call the class directly from within a jsp page? Is the ability of a
jsp page a reduced version of java?

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top