So I am making this builder that is supposed to simply make a config.java file, put the config info it. Compile it. then update an existing jar with it. I have everything working and I am getting no errors, however when I do Runtime.getRuntime().exec("jar uf "+out+" "+ cClass);
it seems to fail. I have tried getting the output of said command but it is showing nothing. I also tried to do this manually and it worked fine. So my question is, what is going wrong and how do I fix it?
Runtime.getRuntime().exec("javac "+config);
File cClass = new File (config.getParentFile().getAbsolutePath() +"/configs.class");
Runtime.getRuntime().exec("jar uf "+out+" "+ cClass);
Out is the Jar file to be updated, config is the config.java cClass is the config.class
Here is My entire UpdateJar class
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
public class cmd extends Thread{
private File out;
private File config;
public cmd(File out, File config){
this.out = out;
this.config = config;
this.start();
}
public void run(){
try {
Thread.sleep(5000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
Process p = Runtime.getRuntime().exec("jar uvf "+out+" "+config.getParentFile().getAbsolutePath()+("/configs.class"));
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
System.out.println(stdInput.readLine());
System.out.println(stdError.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
}
The output it returns is such:
2013-03-28 20:18:58.363 null
2013-03-28 20:18:58.363 [parsing started RegularFileObject[/Users/jorisbolsens/Desktop/configs.java]]
2013-03-28 20:19:04.364 adding: Users/jorisbolsens/Desktop/configs.class(in = 767) (out= 512)(deflated 33%)
2013-03-28 20:19:04.364 null
Out of curiosity I extracted all the files of my out.jar and found that the configs.class
is in fact being put into the jar, it is simply being put into a folder. into users.jorisbolsens.Desktop
to be specific.
I fixed this, It was so simple that I feel really stupid for not trying this at first. I changed the
Runtime.getRuntime().exec("jar uvf "+out+" "+config.getParentFile().getAbsolutePath()+("/configs.class"));
part to
Runtime.getRuntime().exec("jar uvf "+out+" -C "+config.getParentFile().getAbsolutePath()+ " configs.class");
and everything works perfectly now. I would like to thank ericson for all his help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.