Running hadoop jar command from JAVA using Runtime.exec - java

I am trying to run an hadoop jar command from JAVA using Runtime.exec.
Below is the sample code:
Runtime.getRuntime().exec(new String[]{"bin/hadoop", "jar /home/hadoop/jar/test.jar /user/hduser/myinput/input /user/hduser/newoutput"});
However I am not getting the desired output. Below is my hadoop command which I want to execute from JAVA:
bin/hadoop jar /home/hadoop/jar/test.jar /user/hduser/myinput/input /user/hduser/newoutput
I am not getting any exception as well. Is the way Runtime.getRuntime().exec is used is wrong?

Replace your command with following command:
Runtime.getRuntime().exec("HADOOP_HOME/bin/hadoop jar /home/hadoop/jar/test.jar /user/hduser/myinput/input /user/hduser/newoutput");

Give the class name where you defined the driver code.
bin/hadoop jar /home/hadoop/jar/test.jar Package_name.className /user/hduser/myinput/input /user/hduser/newoutput

Related

Launch java command from in_exec Fluentd plugin

I have any problems to configure Fluentd; I want call in_exec plugin to launch Linux bash script that call a jar but it doesn't work.
My code:
<source>
#type exec
format none
tag none
command sh /var/tmp/script.sh
run_interval 5m
</source>
And my script is:
#!/bin/bash
java -jar example.jar
I don't understad where I wrong; if I change script (for example to create a file) all it's OK but if I use java command it doesn't work.
Please help me!
Thanks
Try to update your script with the absolute path to the jar in the sh file. Otherwise, there may be a problem when executing script in different locations and it will fail to find the jar.
#!/bin/bash
java -jar /hom/{User}/{Path to Jar}example.jar

Translation of java commands in Linux systems

I am currently using a linux system to execute a specific command that translates into another java command (java - jar)
For example:
when i try execute /usr/bin/a in terminal, it will read the /usr/bin/a command and translates into 'java -jar' command
I do not want to execute 'java -jar' command directly and i would to specify a full path in executing the command so is there a possible way to achieve this without using a script like /.sh?
Things that i have attempted:
i have tried using the alias command in bashrc files
for example in bashrc file:
alias /usr/bin/a='java - jar'
but when i try to source the bashrc files, it gives me an invalid alias.
I know i can use a /.sh script to execute the command but that is not my intention to do it.
Have you tried to write a bash script with java -jar and execute it ?
You test.sh file will contain:
java -jar test.jar
And after that you can run
./test.sh
And offcourse you can put to bin directory or create an alias for that bash file

Error while executing java program with .sh file

I have error while executing java command with .sh file with external library.
I have wrote a script called executer.cmd which contains
java -cp .;hsql.jar hsqlconnector %*
its working fine with windows.
For Unix also I have wrote a script and make u+x with chmod but still m getting error
of
bash: hsql.jar command not found
My executor.sh looks like
java -cp .;hsql.jar hsqlconnector %*
On Linux you must use : (colon) instead of ; (semi-colon) to separate entries on a path, because ; has a different meaning in the shell on Linux.
See here:
http://www.coderanch.com/t/526784/Linux-UNIX/cp-linux-include-additional-jar

How to run batch file with parameters in java?

I have created a jar file called test.jar under C:\jars. I have JAR file under the same location named run.bat and it contains the below code -
#echo off
set exec_path=C:\jars java -cp %exec_path%/test.jar; com.mycomp.myapp.MyProgram "%1"%*
#echo on
It is running successfully from command prompt with parameters.
Now I would like to run it from another JAVA program.
Please suggest.
Thanks!
I've encountered this issue before. The answer is that you have to run cmd.exe or bash or whatever shell you've got, then feed in the command to that process via the process input/output streams.
Process p = Runtime.getRuntime().exec("cmd");
p.getOutputStream().write("mybatch.bat\n");

Add jar files to classpath at launch time

I want to add some jar files to my binary at runtime, but I keep getting errors. I'm running this on a Windows machine. My code is in a directory called SeleniumTest.
Here is the command I used to compile:
javac SeleniumTest\src\com\src\test\First.java -d SeleniumTest\bin -cp SeleniumTest\lib\junit-4.10.jar;SeleniumTest\lib\selenium-java-2.39.0.jar;SeleniumTest\lib\selenium-server-standalone-2.39.0.jar
This worked successfully. However when I try to run this command:
java -cp SeleniumTest\lib\junit-4.10.jar;SeleniumTest\lib\selenium-java-2.39.0.jar;SeleniumTest\lib\selenium-server-standalone-2.39.0.jar SeleniumTest\bin com.src.test.First
I get a message:
Error: Could not find or load main class SeleniumTest\bin
My code, First.java exists in
SeleniumTest\bin\com\src\test
What am I doing wrong?
try this
java -cp "SeleniumTest\lib\junit-4.10.jar;SeleniumTest\lib\selenium-java-2.39.0.jar;SeleniumTest\lib\selenium-server-standalone-2.39.0.jar;SeleniumTest\bin" com.src.test.First
try following
java -cp SeleniumTest\lib\junit-4.10.jar;SeleniumTest\lib\selenium-java-2.39.0.jar;SeleniumTest\lib\selenium-server-standalone-2.39.0.jar SeleniumTest\bin SeleniumTest\src\com\src\test\First

Categories

Resources