简体   繁体   中英

Launching external jar file from Java application

I want to execute an external jar file from one of my java applications. The jar (program 2) should be immediatly launched when the following code is executed (program 1):

        Process proc = Runtime.getRuntime().exec("c:\\program files\\java\\jre1.8.0_161\\bin\\java -jar C:\\DocumentCloud\\Workspace\\Wordseller_V2\\wordseller_2.jar " + fileName);

Strangely, prgram 2 is not launched immediatly with the above code. Instead, program 2 will be launched after program 1 is finished/closed. I find this behavior rathe strange, but I couldn't find a solution to solve the issue. I already tried to launch program2 from a seperate thread, but this didn't help.

Your support will be appreciated. Thanks a lot in advance.

Bet regards

uli

It is really hard to answer this question without more information, however based on the code you have shown, the issue is likely that because you are not calling waitFor() on the process, your program is asynchronously kicking off this process, and the completing. If you want your program to wait for this other process to complete, you are going to have to block your program's main thread.

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