1

My java uses ProcessBuilder to run several commands using other jar that I have added in the resources.

It works fine in Eclipse, but once I export it to executable jar, it doesn't work:

//Defs Class has this line
public final static String APKTOOLS_JAR_PATH = Defs.class.getResource("/apktool.jar").getPath();

ProcessBuilder pb = new ProcessBuilder("java", "-jar", Defs.APKTOOLS_JAR_PATH, "d", apkPath, "-o", decodePath, "-f");
pb.redirectError(Redirect.INHERIT);
Process p = pb.start();

I get back:

Error: Unable to access jarfile apktool.jar

1 Answers1

1

The Java command executable cannot read a jar file from a jar file. It can only read from the file system. You would have to write the contents of that jar file into a temp file and pass that pathname to the ProcessBuilder.

bmargulies
  • 97,814
  • 39
  • 186
  • 310