我正在开发一个java应用程序,其中一个任务是使用 Runtime exec
. 该命令需要另一个jar文件才能工作,但每当执行该命令的部分时,我都会得到一个“错误:无法访问jarfile”。
首先,我现在的工作目录是:
assets/jarFile.jar
myApp.jar
我的代码是这样的:
try {
// To get the path of the directory where my current running JAR is
String jarPath = myApp.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String path = URLDecoder.decode(jarPath.substring(0, jarPath.lastIndexOf("/")), "UTF-8");
// The system command to execute
String command = "java -Xmx1024m -jar "+path+"/assets/jarFile.jar and-so-on...";
Process p = Runtime.getRuntime().exec(command);
...
}
这个 jarFile.jar
不是一个可执行的jar。
你知道吗?
1条答案
按热度按时间rhfm7lfc1#
似乎查找jar文件路径的代码没有返回正确的路径。