Pregunta

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"
¿Fue útil?

Solución

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)

Otros consejos

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();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top