File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes run bat file within java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "run bat file within java" Watch "run bat file within java" New topic
Author

run bat file within java

Harry Steinke
Greenhorn

Joined: Dec 09, 2005
Posts: 13
I have a bat file with works perfectly when run from Windows. When I try to call it within java I get a
java.lang.NoClassDefFoundError: javax/security/auth/callback/Callback
The bat file uses a vendor jar file.

The following is the bat file with specific info marked out for proprietary reasons.
java -Duser=xxxx -Dpassword=xxxxx -Dhost=xxxxxxxxxxx -Dport=##### -jar c:\xxxxxxxx.jar list agents matching (.*)

The code I am running in my app is:
Runtime.getRuntime().exec("cmd /C start " + [file path] + [bat file name]);

Any suggestions on how to resolve this or where to look for additional information would be appreciated
Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

That class is built into Java 1.4 and later, so it looks like in that particular environment your "java" command is causing a Java 1.3 JRE to be run.
Harry Steinke
Greenhorn

Joined: Dec 09, 2005
Posts: 13
That's interesting and confusing. I checked and my runtime and compiler are both set for 1.4.
Anything else you can think of that I could look at?
Thanks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Is there anything in that bat file that depends on the "current" directory?
Bill
Douglas Kent
Ranch Hand

Joined: Oct 06, 2000
Posts: 171
Try explicitly setting the classpath in your bat file - that's probably just the first class to get loaded in that package, and it's not finding it.
Harry Steinke
Greenhorn

Joined: Dec 09, 2005
Posts: 13
Set the classpath in the bat file - same error.
I don't know of anything that is using a set directory location. There isn't anything in the bat file except where it points to the jar file that it is using.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Off-the-wall idea. Try running a bat file that does java -version

If Java runs at all it should be able to find a class that is in the standard library.
Bill
Harry Steinke
Greenhorn

Joined: Dec 09, 2005
Posts: 13
Well I'll be a ...
The java version that comes up from the bat file is 1.3.1.
I added a cd c:\\ line at the beginning of the bat file that points to my 1.4 version and it works.

Thanks for your help.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: run bat file within java