[英]Resource files in a Java program
l want to be able to run a bat file compiled in my java app.我希望能够运行在我的 java 应用程序中编译的 bat 文件。 Everything runs fine from the netbeans IDE but when l build and run, the cmd is not able to run the resource file bundled in the jar file.
在 netbeans IDE 中一切正常,但是当我构建并运行时,cmd 无法运行捆绑在 jar 文件中的资源文件。 l run the bat file with cmd(Runtime in java).
我用cmd(Java中的运行时)运行bat文件。 From the image below, the application package is the apksec, and others are resource folders with files l want to use in the program, the bat file is in the res folder, When l run the app directly from cmd
从下图中,应用程序包是apksec,其他是资源文件夹,里面有我想在程序中使用的文件,bat文件在res文件夹中,当我直接从cmd运行应用程序时
C:\Users\slab1>java -jar C:\Users\slab1\Pictures\training\dist\ApkSec.jar
l get error我得到错误
'file:' is not recognized as an internal or external command,
The code snippet to run the bat file using cmd below使用下面的 cmd 运行 bat 文件的代码片段
How can l get a path to run the bundled resource file in the jar?我如何获得运行jar中捆绑资源文件的路径?
Please take care of parameters you are passing to exec method.请注意您传递给 exec 方法的参数。 Here is an example from - https://www.tutorialspoint.com/java/lang/runtime_exec_envp.htm
这里是一个例子 - https://www.tutorialspoint.com/java/lang/runtime_exec_envp.htm
public static void main(String[] args) {
try {
// create a new array of 2 strings
String[] cmdArray = new String[2];
// first argument is the program we want to open
cmdArray[0] = "notepad.exe";
// second argument is a txt file we want to open with notepad
cmdArray[1] = "example.txt";
// print a message
System.out.println("Executing notepad.exe and opening example.txt");
// create a process and execute cmdArray and currect environment
Process process = Runtime.getRuntime().exec(cmdArray,null);
// print another message
System.out.println("example.txt should now open.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.