简体   繁体   English

e:java.io.IOException:无法运行程序“ java -jar bg.jar”:CreateProcess错误= 2,系统找不到文件

[英]e: java.io.IOException: Cannot run program “java -jar bg.jar”: CreateProcess error=2, The system cannot find the file

i have a jar file called bg.jar which prints some numbers. 我有一个名为bg.jar的jar文件,其中显示了一些数字。 i want to call this bg.jar from a java program. 我想从Java程序中调用此bg.jar。 i used this code 我用了这段代码

public class bg1 {
public static void main(String[] args) {
    try{
     //  Process ps = Runtime.getRuntime().exec("java -jar bg.jar");
      ProcessBuilder builder = new ProcessBuilder("java -jar bg.jar");
      Process process = builder.start();

    }catch(Exception e){
        System.out.println("e: "+ e.toString());
    }
  }
}

i added bg.jar in the libraries folder of bg1 project. 我在bg1项目的librarys文件夹中添加了bg.jar。 but when i run bg1.class it gives me this error: 但是当我运行bg1.class时,它给了我这个错误:

e: java.io.IOException: Cannot run program "java -jar bg.jar": CreateProcess error=2, The system cannot find the file specified e:java.io.IOException:无法运行程序“ java -jar bg.jar”:CreateProcess错误= 2,系统找不到指定的文件

how can i call bg.jar from bg1.class 我如何从bg1.class调用bg.jar

I think the file not found error is that the system cannot find the "java" executable file. 我认为找不到文件错误是系统找不到“ java”可执行文件。 One way is to add the "java" directory path to the environment variable PATH. 一种方法是将“ java”目录路径添加到环境变量PATH。 To find the variable, right click on the "My Computer"/Advanced system settings/Environment Variables/System variables. 要找到该变量,请右键单击“我的电脑” /“高级系统设置” /“环境变量” /“系统变量”。 Then open a new console, run your Java program above. 然后打开一个新的控制台,运行上面的Java程序。

Alternative way is probably to load the jar file to your Java program. 另一种方法可能是将jar文件加载到Java程序中。 And then run the static main method in your Java codes. 然后在您的Java代码中运行static main方法。 To dynamically load java files, see How to load a jar file at runtime . 要动态加载Java文件,请参见如何在运行时加载jar文件 The class that contains the main method can be found by parsing the META-INF/MANIFEST.MF file in the jar file. 可以通过解析jar文件中的META-INF / MANIFEST.MF文件来找到包含main方法的类。

ProcessBuilder builder = new ProcessBuilder("java -jar bg.jar"); ProcessBuilder builder =新的ProcessBuilder(“ java -jar bg.jar”);

Space does not work in process builder command, I tried using comma separated words, and it worked. 空格在进程生成器命令中不起作用,我尝试使用逗号分隔的单词,并且它起作用了。

Something like this for command "make macosx"- 像这样的命令“ make macosx”-

ProcessBuilder builder = new ProcessBuilder("make" , "macosx"); ProcessBuilder builder = new ProcessBuilder(“ make”,“ macosx”);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.IOException:无法运行程序“mysql”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException:Cannot run program “mysql”:CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“plink”:CreateProcess error=2,系统找不到指定的文件 - java.io.IOException: Cannot run program "plink": CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“sqlldr”:CreateProcess error = 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “sqlldr”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ WMIC”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “WMIC”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ tskill”:CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “tskill”: CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“。\\ bin \\ catalina.bat”-CreateProcess错误= 2,系统找不到指定的文件 - java.io.IOException: Cannot run program “.\bin\catalina.bat” - CreateProcess error=2, The system cannot find the file specified java.io.IOException:无法运行程序“ scala”:CreateProcess错误= 2, - java.io.IOException: Cannot run program “scala”: CreateProcess error=2, ant jar错误:执行失败:java.io.IOException:无法运行程序... $ {aapt}“:error = 2,没有这样的文件或目录 - ant jar error: Execute failed: java.io.IOException: Cannot run program…${aapt}": error=2, No such file or directory java.io.IOException:无法运行程序“dir”:CreateProcess error = 2,Das System - java.io.IOException: Cannot run program “dir”: CreateProcess error=2, Das System
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM