Home arrow static arrow Java Programming [Archive] - Runtime.exec() ... executing a java jar from within an NT command file
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Runtime.exec() ... executing a java jar from within an NT command file
10 Duke Stars available
This topic has 13 replies on 1 page.

Posts:8
Registered: 8/5/04
Runtime.exec() ... executing a java jar from within an NT command file  
Aug 5, 2004 5:48 AM



 
Hello,
I spent the better part of yesterday seeking insight to this with little success. So I hope someone here can direct me in a productive direction.

I set-up my runtime.exec in a manner similar to the article on javaworld.com which is often referred to here, with two threads to empty the output and error streams of the NT command file I am executing.

The command file works perfectly from the command line.

I am currently attempting to build a gui which will automate regression testing for another application. This requires third party software to be running prior to the execution of the test suite. This third party software is started using an NT command file. The command file sets up an environment (classpath, server flags, etc.) and then executes a jar file. When this command file is run from my Gui, the output is identical to the command being run from the command line. Then when the jar file is to be executed, the command file output shows a "file not found" error, but only when executed from my Gui.

My call to runtime exec looks like this.

cmdString = new String("commandtoexecute");
fileLoc = new String("Fully qualified path to command file");
String [] envp = new String[0];

testProcess = Runtime.getRuntime().exec(cmdString, envp, fileLoc);
// some code to process the output streams of testProcess

Other Info:
Gui currently executed within Eclipse IDE
BEA WebLogic is the third party software
 

Posts:319
Registered: 11/8/00
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 5, 2004 5:54 AM (reply 1 of 13)



 
just a thought but do you need to run the test in a seperate JVM? if not then you could just use the java.class rather than the java.exe version. al a Ant.

just me thinking out loud. probably a load of rubbish.
 

Posts:8
Registered: 8/5/04
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 5, 2004 8:31 AM (reply 2 of 13)



 
I am just building a director. Everything should execute as it did before with the single exception of being able to capture and filter the streams associated with each test driver.
 

Posts:6
Registered: 9/23/03
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 6, 2004 1:46 AM (reply 3 of 13)



 
One thing you could check for is the path to your command. If it contains spaces, it will probably fail. When you have spaces in the application path, or in any argument, there is another exec() method that suites better:

String[] cmd = { "command", "arg1", "arg2", ... }String[] env  = { };File dir = new File(workDir);Runtime.getRuntime().exec(cmd, env, dir);


Another thing you can try is to execute it within a shell, that is:

(In Windows)
String[] cmd = { "cmd", "/C", "yourcommand" };...


HTH
 

Posts:8
Registered: 8/5/04
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:32 AM (reply 4 of 13)



 
I've tried this form of Runtime.exec as well with no success. Also, the working directory reported from within the command script just prior to the execution of the command which fails is always the same. It does not matter if I execute the command script from the command line or from Runtime.exec.

Just to rehash:
There is a java program I am running from within an NT command script.
The NT command script is executed by Runtime.exec from within a GUI I am building
The command script is executed by Runtime.exec
However, from my Gui, the java program fails (after being loaded) with a "file not found" error, but does not fail if the command script is executed from the command line.

I am searching for investigative direction to the resolution of this anomaly. Any help is welcome.
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:37 AM (reply 5 of 13)



 
If the script is just executing a Java class, why can't your Java app simply instantiate an instance and call the desired method?

The answer is probably that you jammed all the logic you needed into the main method, and it's the only interface available to clients. If that's true, rewrite that object so it exposes that functionality in a method that your GUI can call.

Sounds like a roundabout way to get one Java object to call another.

%
 

Posts:8
Registered: 8/5/04
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:41 AM (reply 6 of 13)



 
The java app being called is third party software and the command script is used to set a suite of command parameters to the software. Things like Garbage Collection policies, heap sizes, etc. It also serves as an initializer for several other software packages which get instantiated after the failing java app.

So calling the java app directly really is not an option.
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:46 AM (reply 7 of 13)



 
Sorry, I missed the line about WebLogic in your first post.

Still not understanding why your GUI app has to start WebLogic. Usually WebLogic runs as a service on a server and is automatically restarted if the server is rebooted. Why can't your UI simply assume that WebLogic is available on that server? Why must it start WebLogic?

Sorry if these are ignorant questions. I missed your first thread. I'm asking from the point of view of an outsider. I'm trying to determine if you really need to go to Abaline (metaphorically speaking).

%
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:47 AM (reply 8 of 13)



 
Are you using a JUnit based framework like Cactus to automate testing of your EJBs?

http://www.google.com/search?hl=en&ie=UTF-8&q=JUnit+testing+EJBs
http://jakarta.apache.org/cactus/writing/howto_ejb.html

That's what I'd do.

%
 

Posts:8
Registered: 8/5/04
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 7:53 AM (reply 9 of 13)



 
First, my app has the requirement of allowing the user to start WebLogic if it is not already running.
.... Side question ... any recommendations on detecting if it is already running? grin
Second, development is on a hardened system (i.e. very long time getting approval for additional software on the system).

Thank you for you suggestions though. I will read up on Cactus to see if it could help me here.
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 8:00 AM (reply 10 of 13)



 
First, my app has the requirement of allowing the user to start WebLogic if it is not already running.

Unfortunately, I can't change the requirement.

But I would say that in a production environment WebLogic should always be running.

I guess it's an assumption that I'd make a priori. You're jumping through too many hoops to accomplish something that is better solved with a phone call to the server admin: "Please start the WebLogic service."

.... Side question ... any recommendations on detecting if it is already running? grin

Yes, call the server admin and ask why you can't have 99.999% availability of a critical resource.

Second, development is on a hardened system (i.e. very
long time getting approval for additional software on
the system).

Cactus and JUnit are both open source. No fees involved. If you can install a JAR, you can use these tools.

Better yet, you can drive them automatically as part of your Ant build process. A GUI implies a person in front of it to start and monitor the tests. JUnit and Ant are all about automating these things so they're run every time you rebuild and redeploy the code. You get XML reports on test results that are displayable in a browser. You can even e-mail the test summary to all developers so they can see if a test broke the build. If a test breaks, you don't deploy. That's the way to go, IMO.

When you have a working Ant build.xml, the next step is to automate the build completely using a tool like ThoughtWorks' CruiseControl.

Thank you for you suggestions though. I will read up on Cactus to see if it could help me here.

You're welcome. Good luck. Sorry that I'm not more help.

%
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 8:02 AM (reply 11 of 13)



 
one more point: JUnit, Ant, and Cactus would be running on a build machine. They can invoke EJBs running on a devl or test server, but the JARs would be installed on a separate machine for building code. Once the Ant script is finished, you should have a JAR, WAR, or EAR file that's 100% ready to deploy on the server of your choice. Fully tested, ready to go.

That's the way I'd try to set things up.

%
 

Posts:8
Registered: 8/5/04
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 11:51 AM (reply 12 of 13)



 
Just for resolution,

The java api for Runtime.exec() states to get a default environment you need to send a null as the environment array. I was sending an empty environment array and thus getting an empty environment, instead of the default environment.

Thanx to those who offered help.
 

Posts:21,718
Registered: 98-02-20
Re: Runtime.exec() ... executing a java jar from within an NT command file  
Aug 9, 2004 11:59 AM (reply 13 of 13)



 
So this change made it work as you wished?

Thanks for reporting back.

%
 
This topic has 13 replies on 1 page.