Java execute process on linux

前端 未结 2 786
借酒劲吻你
借酒劲吻你 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 19:59

    Since it is another Java program you might want to consider running it in the same process because it's much easier to communicate between the two programs if they live in the same process. Have you tried running the command outside your program? Does it work? What does the meta-inf.mf file in the jar hold? It might be that the classpath in the meta-inf.mf file isn't relative so any dependent jars can't be found.

    0 讨论(0)
  • 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) /*...*/
    
    0 讨论(0)
提交回复
热议问题