Question

I am trying to run jar file from a java program I found this link : here. I use the following code:

ProcessBuilder pb = new ProcessBuilder("CEDDextractor_all_img.jar", "-jar", "cedd/");
    pb.directory(new File("cedd/"));
    Process p = pb.start();

However I m getting the error: Could not load image: Cannot run program "cedd/CEDDextractor_all_img.jar" (in directory "cedd"): CreateProcess error=193, %1 is not a valid Win32 application. I am little bit confused with the paths I need to specify.

Batch command:

java -jar CEDDextractor_all_img.jar -file "file.jpg"
Was it helpful?

Solution

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "CEDDextractor_all_img.jar", "cedd/");
pb.directory(new File("cedd/"));
Process p = pb.start();

the executable is java :-) (could be javaw, too)

OTHER TIPS

It's incorrect to invoke just "java", which might be not in PATH; you should use:

String jarPath = ...;
ProcessBuilder pb = new ProcessBuilder(System.getProperty("java.home")
        + File.separator
        + "bin"
        + File.separator
        + "java", "-jar", jarPath);
Process p = pb.start();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top