“错误:无法访问jarfile”命令使用运行时exec执行

z3yyvxxp  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(341)

我正在开发一个java应用程序,其中一个任务是使用 Runtime exec . 该命令需要另一个jar文件才能工作,但每当执行该命令的部分时,我都会得到一个“错误:无法访问jarfile”。
首先,我现在的工作目录是:

  1. assets/jarFile.jar
  2. myApp.jar

我的代码是这样的:

  1. try {
  2. // To get the path of the directory where my current running JAR is
  3. String jarPath = myApp.class.getProtectionDomain().getCodeSource().getLocation().getPath();
  4. String path = URLDecoder.decode(jarPath.substring(0, jarPath.lastIndexOf("/")), "UTF-8");
  5. // The system command to execute
  6. String command = "java -Xmx1024m -jar "+path+"/assets/jarFile.jar and-so-on...";
  7. Process p = Runtime.getRuntime().exec(command);
  8. ...
  9. }

这个 jarFile.jar 不是一个可执行的jar。
你知道吗?

rhfm7lfc

rhfm7lfc1#

似乎查找jar文件路径的代码没有返回正确的路径。

相关问题