Need help in using Runtime class

Hi all,

I am facing problem with JRE versions of websphere and SUN JRE. Let me explain my problem.

We have an application working fine in websphere, Now my organization wants to migrate this app to websphere. This application downloads some set of jar files to the client side when the user hits the server with some url. These jar files starts th swing based application in the client side , at the same it will try to communicate with EJB's deployed in the server(Now websphere) to get the data for menus and trees in the swing application. Because of different JRE in the websphere commucation problems like class cast exception are happening. Now we are downloading the the Websphere JRE to the client side and trying to start the application with the downloaded JRE(Even it is not required in case of weblogic in the exiting application also they are downloading the sun JRE). Here the problem starts for me. The execute method of Process class is not able to detect the main class. The waitFor method is returning non zero value. Here is my method.

Can anybody guess what's wrong going on with this code.

public Process spawnProcess(String szSpawnCommand) throws

Exception

{

szSpawnCommand = "C:\\ccc\\JRE\\bin\\javaw.exe com.att.suite.client.SuiteAppManager";

System.out.println("starting processs "+szSpawnCommand);

Process oProcess = null;

try

{

// oProcess = Runtime.getRuntime().exec(szSpawnCommand);

Runtime rt = Runtime.getRuntime();

System.out.println("Got runtime.....");

oProcess = rt.exec("c:/ccc/JRE/bin/java com.att.suite.client.SuiteAppManager");

//oProcess.waitFor();

//oProcess = rt.exec("c:/ccc/JRE/bin/javaw -version");

}

catch (Exception ex)

{

// Throw an exception with the reason why the process

// couldn't be spawned

//

// The original message here confused end users - almost always

// occurs due to lack of memory and we cannot determine actual

// reason OS failed to spawn a process.

//

// Changed to correct LCR MR#: 437

// throw new Exception("Unable to spawn process with command: \"" +

//szSpawnCommand + "\".\nSystem Reason: " + ex.getMessage());

//

/*throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");*/

System.out.println("In oProcess.... ");

ex.printStackTrace();

}

// Wait for a second to give the new process a chance

// to run properly

try

{

Thread.sleep(1000);

}

catch (Exception ex)

{

}

final DataInputStream oProcStdOutStream = new DataInputStream(

oProcess.getInputStream());

final DataInputStream oProcStdErrStream = new DataInputStream(

oProcess.getErrorStream());

Thread oProcStdOutStreamThread = new Thread()

{

public void run()

{

try

{

String szLine = null;

while ((szLine = oProcStdOutStream.readLine()) != null)

{

System.out.println("[FromProc1] " + szLine);

}

}

catch (Exception ex)

{

System.out.println("In oProcStdOutStream");

ex.printStackTrace();

}

}

};

oProcStdOutStreamThread.start();

Thread oProcStdErrStreamThread = new Thread()

{

public void run()

{

try

{

String szLine;

while ((szLine = oProcStdErrStream.readLine()) != null)

{

System.out.println("[FromProc2] " + szLine);

}

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

};

oProcStdErrStreamThread.start();

// See if the process is still running properly

int nProcessExitValue = 0;

try

{

nProcessExitValue = oProcess.exitValue();

// nProcessExitValue = oProcess.waitFor();

System.out.println("nProcessExitValue : "+nProcessExitValue);

}

catch (Exception ex)

{

// This means that the process is still running which

// we'll consider a good sign.

nProcessExitValue = 0;

System.out.println("In nProcessExitValue");

ex.printStackTrace();

}

// Check the process exit value

if (nProcessExitValue != 0)

{

// Throw an exception with the return value of the spawned

// process.

// The original message here confused end users - almost always

// occurs due to lack of memory and we cannot determine actual

// reason OS failed to spawn a process.

//

// Changed to correct LCR MR#: 437

// throw new Exception("Unable to spawn process with command: \"" +

//szSpawnCommand + "\".\nProcess Exit Value: " +

//nProcessExitValue);

throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");

//System.out.println("In nProcessExitValue!=0");

}

Here is the error :

starting processs C:\ccc\JRE\bin\javaw.exe com.att.suite.client.SuiteAppManager

Class loaded...

Got runtime.....

nProcessExitValue : 1

[FromProc2] The java class is not found: com/att/launch/jre/Sample

java.lang.Exception: You have insufficient memory to launch this program.

Please quit some other applications and try again.

at com.att.launch.jre.LaunchApp.spawnProcess(LaunchApp.java:525)

at com.att.launch.jre.LaunchApp.spawnCJAS(LaunchApp.java:366)

at com.att.launch.jre.LaunchApp.main(LaunchApp.java:171)

Please help me, I am struggling with this problem from the long time. Or can any body suggest different way to solve this problem instead of downloading the JRE to the client side.

Bhaskar

[5943 byte] By [bhaskarp80a] at [2007-11-27 11:25:14]
# 1

> java.lang.Exception: You have insufficient memory to launch this program.

> Please quit some other applications and try again.

Don't you think this is significant?

sabre150a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 2

Argh!! Unformatted code... BAD Developer! No twinkie!!

Use the code formatting tags when posting code examples otherwise it sends my eyes funny :(

c0demonk3ya at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 3

Hi,

Thanks for reply. That exception is custom message. If the waitFor() or exitValue() methods are retuning non zero then this message is printing blindly.

Please have a look at the code..

Thanks

Bhaskar

bhaskarp80a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 4

> lease have a look at the code..

>

Not until you post it formatted properly.

sabre150a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 5

Hi ,

I am facing problem with JRE versions of websphere and SUN JRE. Let me explain my problem.

We have an application working fine in websphere, Now my organization wants to migrate this app to websphere. This application downloads some set of jar files to the client side when the user hits the server with some url. These jar files starts th swing based application in the client side , at the same it will try to communicate with EJB's deployed in the server(Now websphere) to get the data for menus and trees in the swing application. Because of different JRE in the websphere commucation problems like class cast exception are happening.

Now we are downloading the the Websphere JRE to the client side and trying to start the application with the downloaded JRE(Even it is not required in case of weblogic in the exiting application also they are downloading the sun JRE).

Here the problem starts for me. The execute method of Process class is not able to detect the main class. The waitFor method is returning non zero value. Here is my method.

Can anybody guess what's wrong going on with this code

public Process spawnProcess(String szSpawnCommand) throws

Exception

{

System.out.println("starting processs "+szSpawnCommand);

Process oProcess = null;

try

{

Runtime rt = Runtime.getRuntime();

System.out.println("Got runtime.....");

oProcess = rt.exec("c:/ccc/JRE/bin/java com.att.suite.client.SuiteAppManager");

}

catch (Exception ex)

{

throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");

}

// Wait for a second to give the new process a chance

// to run properly

try

{

Thread.sleep(1000);

}

catch (Exception ex)

{

}

final DataInputStream oProcStdOutStream = new DataInputStream(oProcess.getInputStream());

final DataInputStream oProcStdErrStream = new DataInputStream(oProcess.getErrorStream());

Thread oProcStdOutStreamThread = new Thread()

{

public void run()

{

try

{

String szLine = null;

while ((szLine = oProcStdOutStream.readLine()) != null)

{

System.out.println("[FromProc1] " + szLine);

}

}

catch (Exception ex)

{

System.out.println("In oProcStdOutStream");

ex.printStackTrace();

}

}

};

oProcStdOutStreamThread.start();

Thread oProcStdErrStreamThread = new Thread()

{

public void run()

{

try

{

String szLine;

while ((szLine = oProcStdErrStream.readLine()) != null)

{

System.out.println("[FromProc2] " + szLine);

}

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

};

oProcStdErrStreamThread.start();

// See if the process is still running properly

int nProcessExitValue = 0;

try

{

nProcessExitValue = oProcess.exitValue();

// nProcessExitValue = oProcess.waitFor();

System.out.println("nProcessExitValue : "+nProcessExitValue);

}

catch (Exception ex)

{

// This means that the process is still running which

// we'll consider a good sign.

nProcessExitValue = 0;

System.out.println("In nProcessExitValue");

ex.printStackTrace();

}

// Check the process exit value

if (nProcessExitValue != 0)

{

throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");

}

Here is the error :

starting processs C:\ccc\JRE\bin\javaw.exe com.att.suite.client.SuiteAppManager

Class loaded...

Got runtime.....

nProcessExitValue : 1

[FromProc2] The java class is not found: com/att/launch/jre/Sample

java.lang.Exception: You have insufficient memory to launch this program.

Please quit some other applications and try again.

at com.att.launch.jre.LaunchApp.spawnProcess(LaunchApp.java:525)

at com.att.launch.jre.LaunchApp.spawnCJAS(LaunchApp.java:366)

at com.att.launch.jre.LaunchApp.main(LaunchApp.java:171)

Please help me, I am struggling with this problem from the long time. Or can any body suggest different way to solve this

problem instead of downloading the JRE to the client side.

Bhaskar

bhaskarp80a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 6

Hi ,

I am facing problem with JRE versions of websphere and SUN JRE. Let me explain my problem.

We have an application working fine in websphere, Now my organization wants to migrate this app to websphere. This application downloads some set of jar files to the client side when the user hits the server with some url. These jar files starts th swing based application in the client side , at the same it will try to communicate with EJB's deployed in the server(Now websphere) to get the data for menus and trees in the swing application. Because of different JRE in the websphere commucation problems like class cast exception are happening.

Now we are downloading the the Websphere JRE to the client side and trying to start the application with the downloaded JRE(Even it is not required in case of weblogic in the exiting application also they are downloading the sun JRE).

Here the problem starts for me. The execute method of Process class is not able to detect the main class. The waitFor method is returning non zero value. Here is my method.

Can anybody guess what's wrong going on with this code

public Process spawnProcess(String szSpawnCommand) throws

Exception

{

System.out.println("starting processs "+szSpawnCommand);

Process oProcess = null;

try

{

Runtime rt = Runtime.getRuntime();

System.out.println("Got runtime.....");

oProcess = rt.exec("c:/ccc/JRE/bin/java com.att.suite.client.SuiteAppManager");

}

catch (Exception ex)

{

throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");

}

// Wait for a second to give the new process a chance

// to run properly

try

{

Thread.sleep(1000);

}

catch (Exception ex)

{

}

final DataInputStream oProcStdOutStream = new DataInputStream(oProcess.getInputStream());

final DataInputStream oProcStdErrStream = new DataInputStream(oProcess.getErrorStream());

Thread oProcStdOutStreamThread = new Thread()

{

public void run()

{

try

{

String szLine = null;

while ((szLine = oProcStdOutStream.readLine()) != null)

{

System.out.println("[FromProc1] " + szLine);

}

}

catch (Exception ex)

{

System.out.println("In oProcStdOutStream");

ex.printStackTrace();

}

}

};

oProcStdOutStreamThread.start();

Thread oProcStdErrStreamThread = new Thread()

{

public void run()

{

try

{

String szLine;

while ((szLine = oProcStdErrStream.readLine()) != null)

{

System.out.println("[FromProc2] " + szLine);

}

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

};

oProcStdErrStreamThread.start();

// See if the process is still running properly

int nProcessExitValue = 0;

try

{

nProcessExitValue = oProcess.exitValue();

// nProcessExitValue = oProcess.waitFor();

System.out.println("nProcessExitValue : "+nProcessExitValue);

}

catch (Exception ex)

{

// This means that the process is still running which

// we'll consider a good sign.

nProcessExitValue = 0;

System.out.println("In nProcessExitValue");

ex.printStackTrace();

}

// Check the process exit value

if (nProcessExitValue != 0)

{

throw new Exception("You have insufficient memory to " +

"launch this program. \nPlease quit some other " +

"applications and try again.");

}

Here is the error :

starting processs C:\ccc\JRE\bin\javaw.exe com.att.suite.client.SuiteAppManager

Class loaded...

Got runtime.....

nProcessExitValue : 1

[FromProc2] The java class is not found: com/att/launch/jre/Sample

java.lang.Exception: You have insufficient memory to launch this program.

Please quit some other applications and try again.

at com.att.launch.jre.LaunchApp.spawnProcess(LaunchApp.java:525)

at com.att.launch.jre.LaunchApp.spawnCJAS(LaunchApp.java:366)

at com.att.launch.jre.LaunchApp.main(LaunchApp.java:171)

Please help me, I am struggling with this problem from the long time. Or can any body suggest different way to solve this

problem instead of downloading the JRE to the client side.

Bhaskar

bhaskarp80a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 7

http://forum.java.sun.com/help.jspa?sec=formatting

sabre150a at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 8

For crying out loud!!

Right... no help for you. You have been told twice now to use code formatting tags so instead you post the same message twice without the formatting.

Good luck getting any help

c0demonk3ya at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 9

Correction three times lol

c0demonk3ya at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...
# 10

> The java class is not found: com/att/launch/jre/Sample

Well, where do you specify the classpath when you launch this external java / javaw process? I see no -classpath or -cp command-line options given to it from your code, so it's using the default classpath determined by either the CLASSPATH environment variable (which is NOT recommended to use by the way), or in the absense of that environment variable, it uses the current working directory.

The bottom line is you're suffering from the same newbie mistake everyone makes -- by not properly specifying the classpath to use.

warnerjaa at 2007-7-29 16:03:14 > top of Java-index,Java Essentials,Java Programming...