This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Sorry if this should have been put in one of the categories, couldn't find one that would fit..
I have my main application, let's call it mainApp. I'm making a small application that's checks for updates for mainApp, downloads file and replaces old file "mainApp.jar". What i can't figure out is how i can run the file "mainApp.jar" from inside "updateApp".
I tried this in many syntaxes:
Process proc = Runtime.getRuntime().exec("cmd /C java -jar 'C://Program Files//Frontlinesystems/mainApp.jar' ");
i suspect by running this the "result" from mainApp.jar somehow is stored in the proc variable?
Now that you're reading the output from the process, you can get the information you need from it.
Another, completely different option, is to not use Runtime.exec / ProcessBuilder but call the main method from Java.
1) the JAR file is part of the class path, both at compile time and at runtime. Just call the static main method:
I didn't even notice I copied the double slashes. You don't need those; you would need double backslashes (\\) because backslash is the escape character in Strings.
Using a separate process (either through cmd /c or through a bat file) has the advantage that any System.exit calls in the Java code will not exit your current application. The drawback is that you will need to take care of the issues described in the article I mentioned.