Java execute process on linux

前端 未结 2 788
借酒劲吻你
借酒劲吻你 2020-12-19 19:26

I\'ve been struggling for a while now with this problem and i can\'t seem to fix it. i already have tried different approaches (Runtime.exec(), ProcessBuiler) but none seem

2条回答
  •  死守一世寂寞
    2020-12-19 20:16

    The problem is this:

    String startupCommand = "java -jar \"" + this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replace("%20", " ") + "\"";
    
    /* more stuff */ builder.command(startupCommand);
    

    This means Jav will look for a command named java -jar ...stuff with spaces.... But what you want is, that Java looks for a command named java and give that command several parameters.

    You should use

    /*...*/ builder.command("java", "-jar", jarLocation) /*...*/
    

提交回复
热议问题