I want to call a compiler (nonstandard) located in a folder inside my Java application. So I wrote this code:
Process p = Runtime.getRuntime().exec("closures/bin/javac " + filename);
It worked!
But now I want to pack this compiler along with my .class files in a .jar file. My folder structure is something like that:
-
.class (a lot of classes)
-
closures/ (a folder)
But when the line mentioned above from the jar file (the call to the compiler in a subfolder) is executed, I got this:
Exception in thread "main" java.io.IOException: Cannot run program "closures/bin/javac": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at Main.main(Main.java:44)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
at java.lang.ProcessImpl.start(ProcessImpl.java:81)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:468)
... 4 more
It seem to me a path problem.
What am I doing wrong?
Thanks.
You cannot execute an executable in the jar file. You must extract it before calling
Runtime.getRuntime().exec().Think again,
Runtime.getRuntime().exec()use your OS’s function. Your OS don’t know about.jarfile. You have to extract it.