Executing ANT task from java program
hi i would like to execute an build.xml task from a java program, and i would like to catch potential errors, thanks for you help,
i found Launcher class, but i have the following errors :
Buildfile: build.xml does not exist!
Build failed
here is the code
String argsLauncher[]= {"D:/temp/build.xml"};
Launcher.main(argsLauncher);
....
> i would like to execute an ant task from, a java program.
http://ant.apache.org/manual/antexternal.html
~
Similar Messages
-
Is it possible to execute SAPGUI scripts from java program?
Hi everyone..
I need to develop an java applications that executes the SAPGUI script or any technique that execute set of transaction as client.
Is it possible to execute SAPGUI scripts from java program? if so, how it can be achieved? is there any other technique to achieve above mention scenario?.
it will be more helpful, if docs related to that are shared..
Thanks in advanceOh, bummer. Would be much more convenient if I could just use iTunes for everything. Can't stand WMP. I wonder if WinAmp might be a good compromise?
Thanks for this answer . . .
Sharon -
How to execute system command from java program
Hi all,
I want to change directory path and then execute bash and other unix commands from a java program. When I execute them separately, it's working. Even in different try-catch block it's working but when I try to incorporate both of them in same try-catch block, I am not able to execute the commands. The change directory command works but it won't show me the effects of the bash and other commands.
Suggestions??The code I am using is....
try
String str="cd D:\\Test";
Process p=Runtime.getRuntime().exec("cmd /c cd
"+str);your str string is already having cd in it but again you ar giving cd as part of this command also please check this,i will suggest you to remove cd from str
Process p1=Runtime.getRuntime().exec("cmd /c mkdir
"+str+"\\test_folder");you should say mkdir once you change your path,but here you are saying mkdir first and then cd D:\Test(this is because of str)..please check this
Process p2=Runtime.getRuntime().exec("cmd /c bash");
Process p3=Runtime.getRuntime().exec("cmd /c echo
himanshu>name.txt");
catch(IOException e)
System.err.println("Error on exec() method");
e.printStackTrace();
Message was edited by:
ragas -
How to execute .msi files from java program
Hi friends,
i have written a java program which invokes and thereby execute any executable files like .exe and .bat.
So its working fine with .exe and .bat files, but it is not working with .msi files.......can you please help me how can i execute .msi files as well??
public class Executeexe {
public static void main(String ar[])
try
Process p=null;
Runtime rt=Runtime.getRuntime();
p=rt.exec("D:\\mysql-essential-5.0.83-win32.msi");
p.waitFor();
catch(Exception e)
}here is the programMake sure that the command that's being exec'd works from the cmd line.
Then read this article and do what it says:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Then if you still are having problems explain what "...it is not working with .msi files..." really means, and provide a [SSCCE Example program|http://mindprod.com/jgloss/sscce.html] -
Execute Unix command from Java program running on windows
Hello,
I need to write a java program that fetches file count in a particular unix machine directory. But java program will be running on windows machine.
The program should execute unix list command and fetch the output of that command.
Can anyone help me on this?
Thanks.Hi there,
I had a similiar problem, though years ago. It was to have a java program execute any other. Lately, I've had to have a java program running on a unix machine execute a shell script. Entirely two different scenarios. I'm not sure what you will need for your app, but look into this:
Java Native Interface for executing C/C++ code.
C/C++ Code for launching the program you need to run.
java.lang.Runtime(?).exec(....)
With a combination of that stuff, you can make a launcher for any os that has Java running on it, and with Runtime, you can exec() pretty near any sort of unix shell or app command you'd like.
Good luck.
Tim -
Executing Unix shell from Java Program
Hi,
I have written a java application using Maverick J2sshtools API which connects to a Unix box using SSH.The program authenticates with the remote box successfully,but It dosen't return the environment info or execute the test script.Have attached the complete code.
package shellInteraction;
import com.maverick.ssh.*;
import com.maverick.ssh2.Ssh2Client;
import com.maverick.ssh2.Ssh2Context;
import com.maverick.ssh2.Ssh2PasswordAuthentication;
import com.sshtools.net.*;
import java.io.*;
import java.util.Iterator;
import java.util.Vector;
public class JavaShell{
public static void main(String[] args) {
SshConnector con = null;
SshClient ssh = null;
ShellProcess process = null;
Shell shell = null;
try{
// Create a session to remote host
con = SshConnector.getInstance();
ssh = connectionSetup(con);
System.out.println(ssh);
// Start a session and do basic IO
if (ssh.isAuthenticated()) {
shell = new Shell(ssh);
System.out.println("Authenticated");
if(shell.getEnvironment().hasEnvironmentVariable("hostname"))
System.out.println("We are connected to " + shell.getEnvironment().getEnvironmentVariable("hostname"));
//System.out.println("Remote operating system is " + shell.getEnvironment().getOperatingSystem());
// boolean isWindows = shell.getEnvironment().getOSType()==ShellEnvironment.OS_WINDOWS;
//if(shell.getEnvironment().hasEnvironmentVariable("USERPROFILE")) {
//System.out.println("User home is " + shell.getEnvironment().getEnvironmentVariable("USERPROFILE"));
//} else if(shell.getEnvironment().hasEnvironmentVariable("HOME")) {
//System.out.println("User home is " + shell.getEnvironment().getEnvironmentVariable("HOME"));
// Commands only executed for Unix OS
//if(!isWindows) {
// Execute a script
traverseDirectory(shell);
shell.exit();
ssh.disconnect();
System.out.println("Shell has exited");
} catch(Throwable t) {
t.printStackTrace();
private static void traverseDirectory(Shell shell) throws Exception{
System.out.println("\n\nTraverse Directory");
// Execute a simple script than prints a directory tree
ShellProcess process = shell.execute("bash test.sh ");
try{
process.expect("Total directories", 1000, true);
System.out.print(process.toString());
} catch (ShellTimeoutException ex1) {
System.out.println("TRAVERSE Expect operation timed out. Sending interrupt to kill the process");
process.interrupt();
}finally {
process.close();
static private Ssh2Client connectionSetup(SshConnector con)throws SshException{
Ssh2Client ssh = null;
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("Hostname: ");
String hostname = reader.readLine();
int idx = hostname.indexOf(':');
int port = 22;
if(idx > -1) {
port = Integer.parseInt(hostname.substring(idx+1));
hostname = hostname.substring(0, idx);
System.out.print("Username [Enter for " + System.getProperty("user.name") + "]: ");
String username = reader.readLine();
if(username==null || username.trim().equals(""))
username = System.getProperty("user.name");
System.out.println("Connecting to " + hostname);
* Create an SshConnector instance
con = SshConnector.getInstance();
// Lets do some host key verification
HostKeyVerification hkv = new PasswordHostKey();
con.setSupportedVersions(SshConnector.SSH2);
* Set our preferred public key type
con.getContext(SshConnector.SSH2).setHostKeyVerification(hkv);
((Ssh2Context)con.getContext(SshConnector.SSH2)).setPreferredPublicKey(Ssh2Context.PUBLIC_KEY_SSHDSS);
* Connect to the host
ssh = (Ssh2Client)con.connect(new SocketTransport(hostname, port), username, true);
* Authenticate the user using password authentication
Ssh2PasswordAuthentication passwordAuthentication = new Ssh2PasswordAuthentication();
System.out.print("Password: ");
passwordAuthentication.setPassword(reader.readLine());
if(ssh.authenticate(passwordAuthentication)!=SshAuthentication.COMPLETE) {
System.out.println("Authentication failed!");
System.exit(0);
}catch(Exception ex1) {
throw new SshException(ex1.getMessage(), ex1.getCause());
return ssh;
When I execute the program
Hostname:****
Username [Enter for thaya]: **
Connecting to CATL
The connected host's key (ssh-dss) is
b6:85:91:6b:8b:ea:cb:40:b5:6f:01:2e:66:78:7f:62
Password: *****
SSH2 CATLMSXP62:22 [kex=diffie-hellman-group1-sha1 hostkey=ssh-dss client->server=aes128-cbc,hmac-sha1,none server->client=aes128-cbc,hmac-sha1,none]
Authenticated
Traverse Directory
com.maverick.ssh.ShellTimeoutException: The shell did not return to the prompt in the given timeout period 10000ms
at com.maverick.ssh.Shell.A(Unknown Source)
at com.maverick.ssh.Shell.execute(Unknown Source)
at shellInteraction.ShellInteraction.traverseDirectory(ShellInteraction.java:108)
at shellInteraction.ShellInteraction.main(ShellInteraction.java:68)
This is the error message what i get.use code tags if you want a response,
ive done the same thing once using
ssh2.ethz.ch ie:
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.ServerHostKeyVerifier;
import ch.ethz.ssh2.Session;
the code looked something like this:
try
conn.connect(new ServerHostKeyVerifier() {
public boolean verifyServerHostKey(String hostname, int port, String serverHostKeyAlgorithm, byte[] serverHostKey) throws Exception {
return true;
conn.authenticateWithPassword(username, password);
try {
sess = conn.openSession();
} catch (java.lang.IllegalStateException e) {
return;
// JOptionPane.showMessageDialog(null, "Could not autheticate.\nCheck username and password.\nTerminating.", "Authentication Failed", JOptionPane.ERROR_MESSAGE);
// System.exit(-1);
sess.requestPTY("dumb", 50, 50, 0, 0, null);
sess.startShell();
}and after that sess has getStdIn() and getStdOut() that get the streams from which you read and write. -
Executing exe files from java program
Hi,
I need to execute exe files and pass arguments to them from my java code.
Can you give me guidelines to do that as i haven't done that before.
Thanks.http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
getRuntime() method.
exec() method. -
Execute ConcurrentRequest from java program
In order to execute concurrent request from java program are this 3 lines enough :
1)ConcurrentRequest concurrentrequest = new ConcurrentRequest(oadbtransaction.getJdbcConnection());
2)int i = concurrentrequest.submitRequest("some value", " some value", "some value", null, false, vector);
3)oadbtransaction.commit();
*******************************8
I am asking because while executing ConcRequest from PL/SQL I have to call a functin : fnd_global.apps_initialize(user_id ,resp_id, app_id) prior to executing FND_REQUEST.SUBMIT_REQUEST.
Is there any equivalent in java for apps_initialize?
thanks in advance.hi
u can call the FND_global using callable statement
DBTransaction txn = getDBTransaction();
CallableStatement cs =
txn.createCallableStatement("begin fnd_global.apps_initialize(:1, :2,:3);end;");
try
cs.setString(1, getOADBTransaction().getUserId() );
cs.setString(2, getOADBTransaction().responsibilityId());
cs.setString(3, getOADBTransaction().getApplicationID());
cs.execute();
cs.close();
catch (SQLException sqle)
try { cs.close } catch (Exception(e) {}
throw OAException.wrapperException(sqle);
thanx
Pratap -
Execute shell command from Java
Hi all,
I need some idea for executing shell script from Java programe.
For example i have start.sh script in /tmp/start.sh folder of unix server.
I want to execute shell script from local java code.
Any idea on this.Hi,
Read the following articles/posts, maybe this could help you:
How to execute shell command from Java
Running system commands in Java applications | java exec example | alvinalexander.com
Want to invoke a linux shell command from Java - Stack Overflow -
How can i execute vb scripts in java program
hi
how can i execute any batch files or any other exe files (vb scripts) from java programs
thanksHi,
You use Runtime.exec to execute commands / exe-files. See the documentation (and remember that it will only work on windows):
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
/Kaj -
Execute linux command from java
I wanna execute linux command from java, bu the output has error:
Return code = 1
top: failed tty get
The code as:
import java.io.*;
public class Execute {
public static void main(String[] args) {
try {
final Process process = Runtime.getRuntime().exec("top");
new Thread() {
public void run() {
try {
InputStream is = process.getInputStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) >= 0;) {
System.out.write(buffer, 0, count);
} catch (Exception e) {
e.printStackTrace();
}.start();
new Thread() {
public void run() {
try {
InputStream is = process.getErrorStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) >= 0;) {
System.err.write(buffer, 0, count);
} catch (Exception e) {
e.printStackTrace();
}.start();
int returnCode = process.waitFor();
System.out.println("Return code = " + returnCode);
} catch (Exception e) {
e.printStackTrace();
}Help please.Your code is probably good to run a program, that does not use terminal capabilities.
Program "top" is a little bit more complicated - you have to run it with a real terminal.
Try to run "xterm -e top". You can find an example how to run an external program
from java code in cnd/gdb module on http://cnd.netbeans.org
For example, take a look at openExternalProgramIOWindow() method on this page:
http://cnd.netbeans.org/source/browse/cnd/gdb/src/org/netbeans/modules/cnd/debugger/gdb/proxy/Attic/GdbProxyCL.java?rev=1.1.2.6.2.5&only_with_tag=release551_fixes&view=markup
It runs a command with external terminal.
Thanks,
Nik -
Unable to execute Linux command from Java
Hi,
I am currently working on a code wherein i need to execute Linux command from Java. Below are some of the query i have.
1) Is there any efficient method of running OS commands from Java, rather than using Runtime and Process method.
2) Below is details of my code which fails in execution
**-- Java Version**
java version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b09)
OpenJDK Server VM (build 1.6.0-b09, mixed mode)
-- Program Code ----
Where <path> = Path i put myself
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.*;
public class GetInode{
* @param args
public static void main(String[] args) {
GetInode test = new GetInode();
test.getInode();
public void getInode(){
String command = "/usr/bin/stat -Lt <path>;
System.out.println(command);
Process process;
Runtime rt;
try{
rt = Runtime.getRuntime();
process = rt.exec(command);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader bre = new BufferedReader(isr);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream());
System.out.println(bre.readLine());
System.out.println(br.readLine().split(" ")[7]);
process.destroy();
}catch (Exception ex){
System.out.println("Error :- " + ex.getMessage());
------Output -------------
/usr/bin/stat -Lt "<path>"
/usr/bin/stat: cannot stat `"<path>"': No such file or directory
Error :- null
Can any one help me what is wrong and why i am unable to run the Linux command from Java.For clarity purpose............i m submitting actual code here
--- Code ---
package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.*;
public class GetInode{
* @param args
public static void main(String[] args) {
GetInode test = new GetInode();
test.getInode();
public void getInode(){
String command = "/usr/bin/stat -Lt \"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt\"";
System.out.println(command);
Process process;
Runtime rt;
try{
rt = Runtime.getRuntime();
process = rt.exec(command);
InputStreamReader isr = new InputStreamReader(process.getErrorStream());
BufferedReader bre = new BufferedReader(isr);
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
System.out.println(bre.readLine());
System.out.println(br.readLine().split(" ")[7]);
process.destroy();
}catch (Exception ex){
System.out.println("Error :- " + ex.getMessage());
--- Output ---
[ratz]s0898671: java GetInode
/usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
/usr/bin/stat: cannot stat `"/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"': No such file or directory
Error :- null
-- Linux Terminal --
If i copy the first line from the output and execute on Linux terminal her is the output that i get
[ratz]s0898671: /usr/bin/stat -Lt "/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt"
/afs/inf.ed.ac.uk/user/s08/s0898671/workspace/CASWESBLIN/TestFS/01_FIL_01.txt.txt 12003 24 81a4 453166 10000 1c 360466554 2 0 1 1246638450 1246638450 1246638450 4096
Can you just assist me where am i really making mistake.......i was wondering if the command that i pass from Java....can be executed on Linux terminal why is it faling to run from java.........and when i print the Error Stream for process output........it show cannot Stat....... -
Problem while running dos command from java program
Dear friends,
I need to terminate a running jar file from my java program which is running in the windows os.
For that i have an dos command to find process id of java program and kill by using tskill command.
Command to find process id is,
wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
Code to run this command is,
public class KillProcess {
public static void main(String args[]) {
KillProcess kProcess = new KillProcess();
kProcess.getRunningProcess();
kProcess = new KillProcess();
kProcess.readProcessFile();
public void getRunningProcess() {
String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
try {
Runtime run = Runtime.getRuntime();
Process process = run.exec(cmd);
int i = process.waitFor();
String s = null;
if(i==0) {
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println("--> "+s);
} else {
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
while ((s = stdError.readLine()) != null) {
System.out.println("====> "+ s);
System.out.println("Running process End....");
} catch(Exception e) {
e.printStackTrace();
public String readProcessFile() {
System.out.println("Read Process File...");
File file = null;
FileInputStream fis = null;
BufferedReader br = null;
String pixieLoc = "";
try {
file = new File("ProcessList.txt");
if (file.exists() && file.length() > 0) {
fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
} else {
System.out.println("No such file");
} catch (Exception e) {
e.printStackTrace();
return pixieLoc;
} when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
if i give process.waitFor(), then it's in running mode and program is not completed.
Colud anyone please tell me how to handle this situation?
or Is there anyother way to kill the one running process in windows from java program?
Thanks in advance,
SathishHi masijade,
The modified code is,
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is, "UTF-16");
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
public static void main(String args[])
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
} else {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
System.out.println("Executing.......");
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
}when i execute the above code, i got output as,
Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
and keeps in running mode only.
If i execute the same command in dos prompt,
CommandLine
ProcessId
java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP 2468
If i modify the command as,
cmd.exe /C wmic process where "name='java.exe'" get commandline,processid > 123.txt
and keeps in running mode only.
If i open the file when program in running mode, no contents in that file.
If i terminte the program and if i open the file, then i find the processid in that file.
Can you help me to solve this issue? -
The following code will open 'Notepad'
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec( "notepad" );likewise, I want to open 'Wordpad'
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec( "wordpad" );The above two line code, compiles successfully, but it doesn't give the correct result.
If I give 'wordpad' in start->run->'wordpad', in windowXP means, the Runtime executer opens 'WordPad',
can anyone give the solution to open WordPad from Java Programming.
thanks
Sarwan_GresTry this:
Runtime runt = Runtime.getRuntime();
Process pr = runt.exec("cmd /c start wordpad"); -
Executing a webservice through Java Program
Hi,
I need to execute an webservice in my java program.
I also have the requirmnet of executing a BAPI.
I am using JCO for executing BAPI.
Can anyone help me out in executing a webservice in Java Program.
Regards
PraveenHi,
Check
http://help.sap.com/saphelp_nw04/helpdata/en/24/d0ff2f5d872a468b4643e1fa740569/frameset.htm
and
http://java.sun.com/developer/technicalArticles/J2EE/j2ee_ws/
for consuming a WS
Check http://help.sap.com/saphelp_nw04/helpdata/en/76/4a42f4f16d11d1ad15080009b0fb56/frameset.htm for BAPI called from Java
Eddy
PS. Which type of SDN Ubergeek/BPX suit are <a href="/people/eddy.declercq/blog/2007/05/14/which-type-of-sdn-ubergeekbpx-suit-are-you">you</a>?
Maybe you are looking for
-
LR 5.6 *VERY* slow moving from Library page to Import page
I am running LR 5.6 on Windows 8.1 64-bit with a 3.8 GHz processor. I am having trouble getting to the page to import files. Once I click the "Import" button, it takes about 3 minutes to switch from the library to the import files page. I have set th
-
I have a PC with Windows XP SP3. When I try to print a PDF document, I get the following message: "The document could not be printed. There were no pages selected to print." Of course, I had selected the pages to print. Recently, I had many problems
-
RRI - Assignment Objects different
Hi I am working on a Jump query and am having a problem. My source query has a InfoObjectA (CHAR 10 - WITH ALPHA CONVERSION ROUTINE) and the target query has a different InfoObjectB (CHAR24 - NO ALPHA CONVERSION ROUTINE), the data are the same for bo
-
After the server reboot I can't bring CPS back up in Windows server. Can anyone tell me how to start CPS? i have tried start from JRun but didn't work. Below are the error i got. 10/28 09:22:42 error Deployer Service failed to deploy C:\Program Fi
-
Multiproccesing isn't working [After Effects cc 2014]
I discovered that i could process my after effects videos much faster than now (50 minutes for a 8 second video) so i enabled multiproccesing and everything was okay but when i want to process a video, the video wouldn't process, i thought that afte