为什么Java不会运行此代码?

时间:2017-09-27 12:37:39

标签: java processbuilder

我有一个名为pb的ProcessBuilder。该类具有以下构造函数:

public Server(JSONObject root) {
    this.jv = new JarVersion( (JSONObject) root.get("jarV") );

    this.ram = Integer.parseInt(root.get("ram").toString());
    this.name = root.get("name").toString();
    this.unit = size.valueOf( root.get("size") .toString().toUpperCase() );

    String wpath = Core.serverpath + fls + this.name;

    String cmd = "java -Xmx"+this.ram;
    cmd += this.unit.getShort(this.unit) + " ";
    cmd += "-jar ";

    cmd += wpath + fls + jv.getFullVersion() + ".jar";

    pb = new ProcessBuilder(cmd);
    pb.directory(new File( wpath ));
}

My Current pb有以下命令:“java -Xmx1024M -jar C:\ Users [USERNAME] \ Desktop \ SLV2_DATA \ server \ test \ spigot-1.11.1.jar”。

该路径可用,此命令在CMD.exe中运行,我不知道它为什么不在课堂上?

为什么这个命令无法执行? 这是我得到的错误:

java.io.IOException: Cannot run program "java -Xmx1024M -jar C:\Users\RicheeNektar\Desktop\SLV2_DATA\server\test\spigot-1.11.1.jar" (in directory "C:\Users\RicheeNektar\Desktop\SLV2_DATA\server\test"): CreateProcess error=2, Das System kann die angegebene Datei nicht finden
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at java.base/java.lang.ProcessBuilder.start(Unknown Source)
at org.RicheeNektar.Resources.Server.start(Server.java:90)
at org.RicheeNektar.frames.Console.<init>(Console.java:176)
at org.RicheeNektar.ServerPanel.Core$5.actionPerformed(Core.java:345)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.desktop/java.awt.Component.processEvent(Unknown Source)
at java.desktop/java.awt.Container.processEvent(Unknown Source)
at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue.access$500(Unknown Source)
at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
at java.desktop/java.awt.EventQueue$3.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Caused by: java.io.IOException: CreateProcess error=2, Das System kann die angegebene Datei nicht finden
at java.base/java.lang.ProcessImpl.create(Native Method)
at java.base/java.lang.ProcessImpl.<init>(Unknown Source)
at java.base/java.lang.ProcessImpl.start(Unknown Source)
... 41 more

0 个答案:

没有答案