Problem with the path in the .jar file

I want to call a compiler (non-standard) 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. The structure of my folder looks something like this:

  • .class (many classes)

  • close / (folder)

But when the line mentioned above from the jar file (calling the compiler in a subfolder) is executed, I got the following:

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

I think the problem is the way.

What am I doing wrong?

Thank.

+3
source share
2 answers

You cannot execute the executable in the jar file. You must retrieve it before calling Runtime.getRuntime().exec().

, Runtime.getRuntime().exec() . .jar. .

+2

, , pwd - , ? , .class, , , AT LEAST

Process p = Runtime.getRuntime().exec("../closures/bin/javac " + filename);

.

0

Source: https://habr.com/ru/post/1774640/


All Articles