简体   繁体   中英

How to execute jar command with file name from java

I need to execute jar file from java with following command.

java -jar test.jar >> /home/jarlogfile/test.log &

Its not working me. Cannot create test.log file in that location and process also end.

Coding:

    public static void main(String ar[]){
    ProcessBuilder process = new ProcessBuilder("java", "-jar", "/home/jar/test.jar", ">> /home/jarlogfile/test.log &");
    Process p = process.start();
}

Help me.

  1. Makre sure main class defined in Manifest in that jar flie
  2. Use getOutputStream() method of Process class to write output to file, not >> command

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM