为什么如果我从NetBeans运行一个java项目,它可以工作,但jar文件却不能工作?
我的问题是:为什么如果我从NetBeans运行一个Java项目,它工作得很好,但是如果我为同一个项目创建一个jar文件,有些函数就不工作了? 特别是,下面的代码应该执行一个bat文件(在项目本身的src文件夹中),并将视频从一个目录移动到另一个目录。 实现这一点的java代码是:
String pathMoveBat = new java.io.File("src\\move.bat").getAbsolutePath();
Process move = Runtime.getRuntime().exec(pathMoveBat+" "+username+" "+dateFormat.format(currentDate)+" "+i+"");
还有文件移动。蝙蝠是
cd C:\Users\%1\Videos\LogitechWebcam
FORFILES /M *.wmv /C "cmd /c move @file C:\Users\%1\Desktop\%2\videos\video%3"
# 1 楼答案
这个过程可能会启动,但几乎会立即阻塞,除非您关心它的stderr和stdout流。检查文档
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Process.html
另一件事是,src文件夹通常不会添加到zip中,正如其他人所说,即使是这样,您也无法仅从命令行访问其中的内容