I'm trying to run the command "/home/simulations/scripts/getDsuIp.sh" with no arguments.
When I run this command manually on the machine, it works great! So the file is definitely there, is definitely runnable (755), and is under the same user (root) . The problem comes when I try to run a Java program that executes this file. I only see this problem on one machine, it works in other places, but I'd like to figure out why it's failing.
ProcessBuilder pb = new ProcessBuilder("/home/simulations/scripts/getDsuIp.sh");
Process p = pb.start();
This gives me the following error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
at java.lang.UNIXProcess.init(Native Method)
at java.lang.UNIXProcess.<clinit>(UNIXProcess.java:295)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:136)
at mycompany.PCtrlDsu.main(PCtrlDsu.java:41)
I have also tried other ways to run it as well, resulting in the same error:
Here is one of the ways I've tried using exec to run it:
String[] cmd = {"/home/simulations/scripts/getDsuIp.sh"};
Process p = Runtime.getRuntime().exec(cmd);
InputStream in = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String result = br.readLine();
p.waitFor();
System.out.println ("exit: " + p.exitValue());
p.destroy();
This fails on the second line when it tries to run the "exec" function.
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
at java.lang.UNIXProcess.init(Native Method)
at java.lang.UNIXProcess.<clinit>(UNIXProcess.java:295)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:110)
at mycompany.PCtrlDsu.main(PCtrlDsu.java:55)
I tried implementing this solution: Running Shell Script From External Directory: No such file or directory
String script = "getDsuIp.sh";
try {
Process awk = new ProcessBuilder("/bin/bash", "/home/simulations/scripts/" + script).start();
awk.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
But I get the same error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
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.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
at java.lang.UNIXProcess.init(Native Method)
at java.lang.UNIXProcess.<clinit>(UNIXProcess.java:295)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:143)
at mycompany.PCtrlDsu.main(PCtrlDsu.java:41)
Does anyone know what the "java.lang.UnsatisfiedLinkError: java.lang.UNIXProcess" error means?
Java Version:
java version "1.7.0_79"
OpenJDK Runtime Environment (fedora-2.5.5.0.fc20-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
The error message means that Java can't find a native method to call.
Given that the native method it's trying to call is part of the JRE, I can only suggest that the Java installation on the one affected machine has got fouled up somehow.
If I saw that error message, I would want to completely uninstall Java off that box and reinstall it. However, I don't know whether that's an option for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With