简体   繁体   中英

running an external jar using java

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.

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM