Reputation: 1856
so, I've been doing some searching, and i can find somethings on how to run an external application, but i cant get them to work! I've been working on this for a while, and its really annoying.
what i want to do is run a .jar file in the directory
C:\Program Files\AVTECH\NPS\Files\bin\NPS.jar
and I've tried a bunch of different things with the code
Process p = Runtime.getRuntime().exec("dir goes here");
.
also
Process p = Runtime.getRuntime().exec("C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar");
.
if i'm correct, it uses command prompt to do this? or at least the MS-DOS language. i did some of that kind of thing a few years ago, but i don't remember how one would do this... I've never worked with this kind of thing in java before...
could someone help please? thanks in advance.
Upvotes: 0
Views: 1751
Reputation: 2702
You need to run the command as a call to the executable and a set of arguments. Check this version of Runtime.exec(String[] cmdarray). If need be, there's also a version of Runtime.exec()
that takes a base directory in which to start the executable.
Upvotes: 0
Reputation: 32697
The actual command should be java -jar C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar
. I mean -- if the jar file is indeed executable, this doesn't mean it will run, by just trying to invoke it. You need to tell Java to run it as shown above.
In addition, MS-DOS is not a language -- it stands for Microsoft Disk Operating System. Nowadays, you have this as a Command-line Prompt (Shell) built into Windows.
Upvotes: 1
Reputation: 3525
Runtime.exec() is working just like if you were typing a command.
Launching a jar file is not working : you have to invoke
java -jar /path/to/my/jar
Check Oracle's documentation on how to execute a jar file.
Upvotes: 3