英文:
java.io.IOException: Cannot run program "java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main": error=2, No such file or directory
问题
I've tried to restart my Java Application with this code:
public static void restartApplication() throws URISyntaxException, IOException {
final File currentJar = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
/* is it a jar file? */
if (!currentJar.getName().endsWith(".jar"))
return;
/* Build command: java -jar application.jar */
final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");
builder.inheritIO();
builder.start();
System.exit(0);
}
When I type the command into my command panel, it works totally fine.
So what is the error here?
Output
java.io.IOException: Cannot run program "java -Xmx512m -cp
/opt/Nils.jar dev.keksstudios.core.Main": error=2, No such file or
directory
英文:
I've tryied to restart my Java Application with this code:
public static void restartApplication() throws URISyntaxException, IOException {
final File currentJar = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
/* is it a jar file? */
if(!currentJar.getName().endsWith(".jar"))
return;
/* Build command: java -jar application.jar */
final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");
builder.inheritIO();
builder.start();
System.exit(0);
}
When I type the command into my command panel it works totaly fine.
So what is the Error here?
Output
> java.io.IOException: Cannot run program "java -Xmx512m -cp
> /opt/Nils.jar dev.keksstudios.core.Main": error=2, No such file or
> directory
答案1
得分: 0
>final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");
这行是错误的。Java/操作系统会寻找名为 java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main.exe
的可执行文件。你需要将参数分开写,像这样:
final ProcessBuilder builder = new ProcessBuilder("java", "-Xmx512m" ,"-cp", "/opt/Nils.jar", "dev.keksstudios.core.Main");
英文:
>final ProcessBuilder builder = new ProcessBuilder("java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main");
This line is false. Java/The OS will look for an executable called java -Xmx512m -cp /opt/Nils.jar dev.keksstudios.core.Main.exe
.
You have to separate the arguments like this:
final ProcessBuilder builder = new ProcessBuilder("java", "-Xmx512m" ,"-cp", "/opt/Nils.jar", "dev.keksstudios.core.Main");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论