Running Maven Command From Java Program (From Eclipse) Mac OS - java

I want to run Maven command from Java in Mac but I am getting the following error:
Exception in thread "main" java.io.IOException: Cannot run program "mvn": error=2, No such file or directory
My code looks like this:
p = Runtime.getRuntime().exec("mvn -version");
If I run the following command, it works fine. The only issue is related to Maven:
p = Runtime.getRuntime().exec("ls -ltr");

check to see if you have <mvn_installation_location>/bin in your /etc/paths.

Related

Issue while calling Python(Anaconda) from Java

I am calling Python(Anaconda) code from Java using ProcessBuilder. It was working fine when I had installed only Python. But now I have removed Python and installed Anaconda. The code to call Python is not working now.
Getting the following error.
com.api.ai.helper.MLPythonAPI callPyhonScriptToPredict
SEVERE: null
java.io.IOException: Cannot run program "python": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at com.api.ai.helper.MLPythonAPI.callPyhonScriptToPredict(MLPythonAPI.java:66)
I am using python 3.6.1(anaconda3 4.4.0 64 bit) and following code to execute Python
ProcessBuilder pb = new ProcessBuilder().inheritIO().
command("python", "C:\\my_code\\test.py", userSays, filePath);
Process p = pb.start();
p.waitFor();
Can somebody help me in this.
I passed the complete Python path in command method(in stead of "python" and now it is working fine.

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

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.

Cannot run program "cf": error=2, No such file or directory and error=2

This question is regarding "cf" - cloudfoundry. I have installed eclipse Mars on Mac. Also have installed cf and run a brew intsall protobuf. I am executing the following in my program from eclipse :
p = Runtime.getRuntime().exec(cmd);
This is giving me:
Cannot run program "cf": error=2, No such file or directory and
error=2, No such file or directory errors.
The cf command works fine from the command line but I see this error while running any cf commands from eclipse.

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";

Executing cmd.exe commands from Java

I'm trying to read a file from the user, in which each line is a cmd.exe command, and run it (it's okay to assume the commands are legal), but when I give a command like echo hi, I get runtime exception error:
Exception in thread "main" java.io.IOException: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified
I'm trying to run the commands like this:
Runtime.getRuntime().exec(command);
where command = "echo hi". This does work for commands like regedit though, so it seems the runtime I'm getting is like the "run" window and not cmd. Is there a way to run these commands?
That's because echo is not an external executable command (i.e., there is no echo.exe file on your hard disk, unless you put it there yourself). It's an internal command of the shell.
You'll probably find that you need to execute something like:
cmd.exe /c echo hello

Categories

Resources