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 have tried getting the output of said command but it is showing nothing.
? Could you please show us the code? – ericson Mar 28 '13 at 5:34Process p = runtime stuff
then used in.readLine() to get whatever the runtime returned, but it returned nothing, just like it does when done manually. – joris bolsens Mar 28 '13 at 5:57InputStream
andErrorStream
? – ericson Mar 28 '13 at 6:32Process.waitFor
method invocation afterjavac
command. Try adding it? – ericson Mar 29 '13 at 3:32jar tf <foo.jar>|grep configs.class
to check if the class is in the right directory. – ericson Mar 29 '13 at 8:02