gpt4 book ai didi

java - 迁移到 Spring Boot 后 ProcessBuilder 找不到可执行文件

转载 作者:太空宇宙 更新时间:2023-11-04 14:54:47 24 4
gpt4 key购买 nike

我有一个使用 Quartz 作为任务运行的 java 类(作为 Java CMS 中的插件)。我现在将其从 CMS 移至 Spring Boot (v1.0.2) 项目,并使用 @Scheduled 注释。

问题是 ProcessBuilder 报告缺少可执行文件,但 File().exist() 返回 true。

它是 FreeBSD 9.2 上相同的 Java 版本 OpenJDK 7、相同的应用程序容器 (Tomcat 7)。

测试代码如下:

package test;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class SchedulerTest {

@Scheduled(fixedDelay=1800000, initialDelay=5000)
public void test() {

if ((new File("/usr/local/bin/exiftool")).exists()) {
System.out.println("Found exiftool");
}
else {
System.out.println("Did not find exiftool");
}

List<String> args = new ArrayList<String>();
args.add("/usr/local/bin/exiftool");
args.add("-n");
args.add("-S");
args.add("-DateTimeOriginal");
args.add("/image/TEST.JPG");
Process proc = null;
try {
proc = new ProcessBuilder(args).start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (proc != null) {
System.out.println("ExifTool output: " + proc.getOutputStream());
proc.destroy();
}
}

}

输出是:

2014-04-28 12:30:49.471  INFO 22473 --- [ost-startStop-7] o.s.boot.SpringApplication               : Started application in 10.997 seconds (JVM running for 4022.804)
Found exiftool
java.io.IOException: Cannot run program "/usr/local/bin/exiftool": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at no.hoanglai.service.SchedulerTest.test(SchedulerTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:184)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 14 more

可能是什么问题?我的猜测是从 Quartz 迁移到 @Scheduled。我也尝试过创建 cutsom bean 并将线程池设置为 2,但没有任何运气。

最佳答案

也许是文件格式问题(不是真正可执行的?)。例如。看到这里"aapt" IOException error=2, No such file or directory" why can't I build my gradle on jenkins? .

关于java - 迁移到 Spring Boot 后 ProcessBuilder 找不到可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com