Possible Duplicate:
Execute another jar in a java program
I try to run a jar file of with a java application from within another java application, but I cannot get it to work. My code is below
// run Jar in other java application
Runtime run=Runtime.getRuntime();
run.exec("java -jar ManichemManagerRotas BatchProcess 8 2012");
I try to run manichemmanagerrotas.jar
with three arguments.
all method i can do it but it cannot work still problem is cannot run jar file's main method class if you have any idea of this problem,plz give me replay me it's important task for me
i try to run jar file then error is that :Unable to access jarfile ManichemManagerRotas
Try to add missing .jar:
Runtime run=Runtime.getRuntime();
run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012");
... and you have to consume the process output... Like this:
InputStream in = run.getInputStream();
InputStream err = run.getErrorStream();
If you want to invoke the java class/functions from another class means, make it as jar and add the jar into your projects build path. In another class you create object of the Jared class and invoke the function. (make sure your class and function is public access)
May be you forgot to type .jar
run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012");
The Runtime.exec(...)
methods returns a java.lang.Process
instance.
Just call its getInputStream()
method.
Process p = run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012");
InputStream is = p.getInputStream();
If you want just write output to some file without modifying it you can just add:
> somefile.txt
at the end of the 'command':
run.exec("java -jar ManichemManagerRotas.jar BatchProcess 8 2012 > somefile.txt");