Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

!!running external app issue  RSS feed

 
Danie Van Eeden
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, im trying to run an external app also written in java.
im using the following code.
public void RunExternalFile(String path)
{
try {
Runtime rt = Runtime.getRuntime();



Process prcs = rt.exec(path);


InputStreamReader isr = new InputStreamReader( prcs.getInputStream() );
} catch(IOException ioe) {}


}

if (e.getSource() == btnStockMaintenance)
{
RunExternalFile("C:\\My Documents\\Autopage\\Stock\\stock.exe");
dispose();
System.exit(0);

PROBLEM:
I can run any application written in JAVA except when it uses packages contained elsewhere. It gives me a ClassdefNotFound Exception.
Any project without importing packages runs fine. The menu program (that launches other program) can be found in c:\folder\menu.
all the other programs that need to be launched are found in c:\folder\itsowndirectory
thus i run my menu program from c:\folder\menu and it runs (for eg) c:\folder\stock\stock.exe.
my guess is that the default app directory for stock is changed to the default directory of menu because the executing path is exeactly that.
any help would be appreciated to solve this or if u could perhaps indicate how to change a projects default executing path asap.
regards
}
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, you could write batch files to start your external programs. Inside do something like:
cd c:\folder\newprogdir
@start java yourprogram
You'd have to figure out the batch scripting, but it should work. It does under linux where I did something similar in a batch file. under windows it might work as well. Or you could manually make a shortcut and then call that shortcut. Windows shortcuts include the working directory of their target. Just make sure that you use the extension(.lnk) on the shortcut name when you call it.
Try those and see if they work. It should be fairly easy to test them. I like the batch file method because you can call all your classpath locations and other settings inside.
HTH
Chris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!