Reputation: 877
I have a java class running as a task (as a plugin in an Java CMS) which used Quartz. I am now moving it out of the CMS and into a Spring Boot (v1.0.2) project and am using @Scheduled annotation.
The problem i that the ProcessBuilder reports missing executable file, but a File().exist() return true.
It is the same Java version OpenJDK 7, same Application Container (Tomcat 7), on FreeBSD 9.2.
The testing code is a follow:
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();
}
}
}
The ouput is:
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
What may be the problem? My guessing is the move from Quartz to @Scheduled. I have also tried to create cutsom bean and set the thread pool to 2, without any luck.
Upvotes: 1
Views: 1631
Reputation: 58124
Maybe a file format problem (not really executable?). E.g. see here "aapt" IOException error=2, No such file or directory" why can't I build my gradle on jenkins?.
Upvotes: 0