1

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"
Community
  • 1
  • 1
Jose Ramon
  • 5,572
  • 25
  • 76
  • 152

2 Answers2

1
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)

cadrian
  • 7,332
  • 2
  • 33
  • 42
1

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();
Dmitry Ginzburg
  • 7,391
  • 2
  • 37
  • 48