-1

i am trying to run a jar file on a linux machine which contains a java code which is trying to execute another .jar file. After going through forum suggestions i tried to create a symbolic link between "/usr/bin/java" and "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java /usr/bin/java". Also i tried reinstalling java 7 but no luck.

command that i am running on linux machine

"java -jar RSFlowInvoke.jar -host -flow -u "user" -p "password"

this further executes a jar file using below method

if(osname.toLowerCase().contains("linux"))
        {
            String currentPath=Paths.get(".").toAbsolutePath().normalize().toString();
            cmd = "java -jar JRSFlowInvoke.jar";
            // tried this simple command also..no luck
            // cmd = "java -version"
            ProcessBuilder builder = new ProcessBuilder(cmd).directory(new File(currentPath));
            //.directory(new File(currentPath2+"/originalJRS"))
            Process process = builder.start();

            StringBuilder output = new StringBuilder();

            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));

            String Line;
            while ((Line = reader.readLine()) != null) {
                output1.append(Line + "\n");
            }

            int exitVal = process.waitFor();
            if (exitVal == 0) {
                System.out.println("Flow launched successfully !!!!");
                System.out.println("----------------------------");
                System.out.println("\n");
                System.out.println(output1);
                System.exit(0);
            } else {
                //abnormal...
            }
        }

it throws this error :

java.io.IOException: Cannot run program "java -jar JRSFlowInvoke.jar" (in directory 
  "/home/employers/JRSFlowInvoke/originalJRS"): error=2, No such file or 
    directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
    at simpleCommand.main(simpleCommand.java:56)
    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.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

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:187)
    at java.lang.ProcessImpl.start(ProcessImpl.java:130)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
    ... 6 more

I made sure that the file is present at the directory.

Any help is really helpful...

  • 2
    You're confusing terms here. `java -jar JRSFlowInvoke.jar` is being interpreted as the name of the whole program to execute. You should execute `java` command and pass `-jar JRSFlowInvoke.jar` as arguments to the command. – Luiggi Mendoza Jan 17 '19 at 17:11
  • The arguments to `new ProcessBuilder()` is an array of values, the first value being the program to execute. You're telling it to run program "java -jar JRSFlowInvoke.jar" (a name with spaces) without any arguments. You need to tell it to run program "java" and supply 2 arguments, i.e. `new ProcessBuilder("java", "-jar", "JRSFlowInvoke.jar")` – Andreas Jan 17 '19 at 17:11
  • Read the error log as a first step towards debugging. – Rajeev Ranjan Jan 17 '19 at 17:21
  • Duplicate of [ProcessBuilder gives a “No such file or directory” on Mac while Runtime().exec() works fine](https://stackoverflow.com/q/10735415/5221149) – Andreas Jan 17 '19 at 18:20
  • Thanks this worked – Roshan Sharma Jan 17 '19 at 18:44

1 Answers1

0

Repaced the arguments to new ProcessBuilder(). replaced with:- new ProcessBuilder("java", "-jar", "JRSFlowInvoke.jar") . . . . . it worked