"/bin/bash" command not found in self executable JAR - java

I have written the following code in my file.
String[] strg = new String[]{"/bin/bash","-c","ffprobe -v quiet -print_format json -show_format -show_streams /Users/pftadmin/Desktop/PFTDEMO_Mp4_24.MP4"};
Process p = Runtime.getRuntime().exec(strg);
I have exported it as a self executable JAR. When I am running the JAR from terminal using java -jar myJar.jar, It runs fine with no error.
But when I am directly executing it by double click, it is showing below error.
can not run program "/bin/bash" : error=2, No such file or directory
Please help me.

Related

ProcessBuilder unable to find Kotlin in path

When I run:
new ProcessBuilder("kotlinc", "-help").start();
I get the error: Cannot run program "kotlinc": CreateProcess error=2, The system cannot find the file specified
I've tried:
If I check my path from windows, it contains C:\Apps\kotlinc\bin, and when I open explorer at that location, there's a file named kotlinc.
If I open cmd.exe anywhere, and run kotlinc, it works just fine.
If I print out my environment:
System.out.print(new ProcessBuilder("kotlinc", "-help").environment().get("Path"));
it contains C:\Apps\kotlinc\bin
If I run new ProcessBuilder("python3", "file.py").start(), it works just fine.
Rebooting my machine
Changing kotlinc to use the full file path is not an acceptable solution, as this is being run across multiple computers and platforms.
As far as I can tell, everything is setup correctly.
Why can't I run kotlinc from ProcessBuilder?
kotlinc is actually a batch file (kotlinc.bat), not a binary file. Therefore, you need to start it by executing the command cmd /c kotlinc.

Making a ImageJ .jar from command line

I have modified a ImageJ source code and i have compiled from command line, using the javac command, but Im trying to create a .jar file and I need help.
It is the first time that I'm trying to compile and create .jar from command line. When I created the .jar, I did the next command:
jar cf test.jar ImageJ/ij/*
Directory "ImageJ/ij/" contains the compiled code.
It doesn't fail but when I'm trying to execute the .jar It returns the error "Failed to load Main-Class manifest attribute from test.jar". When I execute a .jar I always do "java -jar file.jar" but, in this case, It doesn't work.
If I execute "java -cp test.jar ij.ImageJ" (ij.ImageJ is the Main Class) It works but I need to execute a macro in Batch mode and... It fails.
java -cp test.jar ij.ImageJ -batch ../MacrosIJ/helloWorld.ijm
Exception in thread "main" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
...
If I create the .jar in Eclipse It works perfectly, Can someone explain what i am doing wrong?.
If someone can help I will be grateful. Thanks!!
The recommended way to build ImageJ from source is using Maven:
git clone https://github.com/imagej/ImageJA.git
mvn
cd target
java -cp ij-1.50.jar ij.ImageJ

command line: Unable to access jarfile eps2pgf.jar

I'm working with a Mac OSX version 10.9.5 and I am a complete newbie to using the command line and running java files in it.
I just downloaded the eps2pgf folder, I unzipped it and I downloaded JDK8.
However when I try to run the command (thats given in the manual) in my Terminal, I get the following error:
Unable to access jarfile eps2pgf.jar
The exact command I use is:
java -jar eps2pgf.jar Bifurcatiediagram.eps -o Bifurcatiediagram.pgf
So in total the command before I run it is (with what is automatically there as well):
mbpvanasteyaert:~ Aranka$ java -jar eps2pgf.jar Bifurcatiediagram.eps -o Bifurcatiediagram.pgf
What am I doing wrong? Should the eps2pgf unzipped folder be in a specific folder/directory or...?

Java: Unable to access jarfile when running as an admin

I have a jar file named test.jar, which I am running with a batch script from the same folder.
Here's the batch code:
java -jar test.jar
pause
The jar itself works with no problems, and I can run it just fine.
However, if I try to run the batch file as an administrator (by right clicking it and choosing "Run as Administrator"), I get the following error:
Error: Unable to access jarfile test.jar
I'm using Windows 8.1, but this also happened on a machine running Windows 7.
What can I do to be able to run this as an Administrator?
i had the same problem that you and i solved it by changing
java -jar test.jar
to
java -jar %~dp0test.jar
%~dp0 holds the directory of your bat file (AFAIK) so %~dp0 will give Java the full path to the jar file solving the problem.
You could also ad a temp path to java
path=C:\Program Files\Java\jre1.8.0_40\bin
Java script
path=

How to execute my own commands on terminal from java File

I am trying to make a eclipse project in Java to launch commands with some buttons. The libraries of Ros fuerte (These ones i want to use) are correctly installed and concretly i am trying to launch a ros command from a Java File using:
String cmd = "roscore";
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(cmd);
If i launch this command from a current terminal it works, but if i do it from the java file i have a problem because the terminal doesnt recognize the command.
java.io.IOException: Cannot run program "roscore": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:475)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:448)
at java.lang.Runtime.exec(Runtime.java:345)
at LaunchTerminal.main(LaunchTerminal.java:24)
I think that i need to add some path or similar but i dont find the information. Does anybody know how to do it?
Thank u.
only normal commands are possible to execute like rm or cd ... al others must be referenced with full path of context
Do the following if you are using the groovy distribution:
String cmd = "source /opt/ros/groovy/setup.bash && roscore";

Categories

Resources