Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a java program, that has been exported to a runable .jar file. This jar run correctly in a windows cmd. I execute typing this:

java -jar completerute.jar

It runs correctly (execution lasts about 1 minute) and generates a file as result. All perfect.

But when I try to execute this in other project by typing this:

Process p = Runtime.getRuntime().exec("java -jar "+completerute.jar);

p.waitFor(); <--- this is because i need to wait for the .jar finish to read the file that it generates

The call is correct but it INSTANTLY says that has finished (p.waitFor() sets green light to continue the normal execution). But the resulting file of the .jar application hasn´t been generated. I think that this is because the call has been done but the jar application hasn't been executed. I don't know why......

And I hope you could give me some orientation about the cause of the problem. Thank you for your attention.

EDIT: exact code from the source file is here

System.out.println("Calling jar process");
Process p = Runtime.getRuntime().exec("java "+System.getProperty("user.dir")+"\\esclavomaude.jar "+parametros);
p.waitFor();//waiting for finish
System.out.println("jar call finished");

Aclarations: System.getProperty("user.dir")---> provides the actual path of the project which is on execution. my jar is on that directory.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.5.6.2554\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nosc"], "copyright__copyright__copyright": ["time.getRuntime().exec(\"java \"+System.getProperty(\"user.dir\")+\"\\\\esclavomaude.jar \"+parametros);\np.waitFor();//waiting for finish\nSystem.out.println(\"jar call finished\");\n\nAclarations: System.getProperty(\"user.dir\")---> provides the actual path of the project which is on execution. my jar is on that directory.\n\nshare|improve this question\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nBrowse other questions tagged or ask your own question."]}