Executing jar command from the java application

Hi All,
In my application i want to create a jar file with the existing class @ Runtime and want to download . But i tried to execute the jar command via Process.getRuntime, it throws IOException. Please guide me or give the solution

PavithraKarthikeyan wrote:
Please guide me or give the solutionQuestion your need for this. Why do you think you need to create the jar file.
P.S. The jar command is only available if the user has the JDK installed so if he has only the JRE installed then you have a problem using Runtime.exec(). There are classes (java.util.jar.JarFile et al) that will allow you to jar files using Java code.

Similar Messages

  • Can we execute DOS Commands from a Java Application

    I just want to know whether we can execute DOS Commands from a Java Application.
    Thanks.

    hi,
    try this:
    Runtime.getRuntime().exec("cmd /c start abc.bat");
    andi

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • How to execute *.BAT file from  the Java Application

    Hello to all.
    I wants to run *.BAT file form my applicaion.
    Can u give the code of that two-four line,please
    Wating four your replay.
    Yours Friend
    Bhavin Shah.....

    pr = rt.exec("cmd.exe /c start " + yourProgramName)The exec() method executes the command you specify in the argument and returns a process. In this example, it's telling Windows to run "yourProgramName".
    HTH

  • Running a dos command from a java application

    hello,
    I'm trying to execute a batch file from a java application. I tried with:
    try
    Process proc=Runtime.getRuntime().exec("fop -fo "+iXmlFoFile+" -
    svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                               the Xml FO file into Svg file: "+e);}
    and with:
    try
    Process proc=Runtime.getRuntime().exec("cmd ./c fop
    -fo "+iXmlFoFile+" -svg "+SvgFileName);
    }catch (IOException e){System.err.println("Error in conversion of
                the Xml FO file into Svg file: "+e);}
    but i have a IOException: CreateProcess: .... error=2
    When I try these line to launch a .exe file it works but not with a .bat file.
    I also tried:
    String execstr = "fop -fo "+iXmlFoFile+" -svg "+SvgFileName;
    String [] commandArray = { execstr };
    try {
    Runtime.getRuntime().exec(commandArray);
    } // end try
    catch ( Exception e ) {
    System.out.println( e.getMessage() );
    e.printStackTrace();
    }// end catch
    but i got the same exception in java.lang.Win32Process.create
    What did i do wrong?

    Your execution string is a bit more that I want to figure out, but here are a couple ideas:
    Is the working directory of any importance? If so you'll need to set that when you do your exec()
    I think I remember reading something about batch files that couldn't be kicked off via this method. Perhaps you need to execute the string "start mybatchfile.bat". Seems like you need to do something like that to get a command interpreter to run your batch file.

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • Runnig DOS commands from the java code?

    Hi reader,
    how can I execute DOS commands (I am on an Windows XP Machine) from my java code and also capture the output?
    I think the
    runtime.exec(command)
    only executes win32 processes.
    Please suggest
    TIA
    Ayusman

    Again, this link should tell you most of what you need to know:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    You're not limited to the Win32 platform unless you're using specific DOS commands. Perhaps if you're just after file system information then some of the classes in the java.io package can help.
    If it's not enough, perhaps a resource bundle or something similar can provide you with the names of the external programs you need to run, i.e. "dir" for win and "ls" for *nix.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Executing DOS command from within java.

    I have an XML file and an XSLT stylesheet.
    I want to process this XML file using XSLT stylesheet from java. Using saxon.
    Here is the java class I wrote --
    class DOSCommand {
    public void exec_command(String[] cmd) {
    try {
    Process child = Runtime.getRuntime().exec(cmd);
    } catch (IOException e){
    System.out.println("Error");
    System.out.println(e.getMessage());
    finally{
    System.out.println("Finally");
    In my servlet class I am instantiating the DOSCommand object and calling the method
    DOSCommand d = new DOSCommand();
    String[] c = {  "c:\\Program Files\\saxon\\saxon.exe", "-o",
    "PO.html", "ePO.xml", "POE.xsl"
    d.exec_command(c);
    But I am not getting results. It does not give any error. But does not process the XML file and the Date/timestamp of PO.html does not change.
    I know that Definition/Creation of DOSCommand object is not necesssary here. But we can disregard it.
    Please let me know where I am going wrong !
    Avinash.

    Probably where you are going wrong is in failing to specify your working directory, so your command can't find "PO.html" and so on in the default working directory for that command. But that's not really the answer. The answer is not to do it in that way in the first place. Saxon has a Java API and its documentation has a section entitled "Embedding Saxon in an application".

  • Help on accessing tables of SAP from the Java Application

    Hi All
    I want to access some tables available in SAP through my Java program.  Do I have to write any code for database connectivity or straightaway I can write SQL statements in my Java code?
    Can anyone please suggest the sample code for this?
    Thanks in Advance,
    Vijay.

    the above one is with out connection pool, check this with connection pool.
    import com.sap.mw.jco.*;
    public class JcoTest {
    private static JCO.Client theConnection;
    private static IRepository theRepository;
        private static final String POOL_NAME = "myPool";
    public static void main(String[] args) {
        JCO.Pool connPool = JCO.getClientPoolManager().getPool(POOL_NAME);
        if (connPool == null) {
          JCO.addClientPool(POOL_NAME,
                            5,      //number of connections in the pool
                            "client",
                            "username",
                            "paswword",
                            "EN",
                            "hostname",
                            "00");
            theConnection = JCO.getClient(POOL_NAME);
      retrieveRepository(); 
      try {
      JCO.Function function = getFunction("RFC_READ_TABLE");
      JCO.ParameterList listParams = function.getImportParameterList();
      listParams.setValue("BSAUTHORS", "QUERY_TABLE");
      theConnection.execute(function);
      JCO.Table tableList = function.getTableParameterList().getTable("DATA");
      if (tableList.getNumRows() > 0) {
       do {
        for (JCO.FieldIterator fI = tableList.fields();
          fI.hasMoreElements();)
          JCO.Field tabField = fI.nextField();
          System.out.println(tabField.getName()
               + ":t" +
               tabField.getString());
         System.out.println("n");
       while (tableList.nextRow() == true);
      catch (Exception ex) {
       ex.printStackTrace();
      JCO.releaseClient(theConnection);
    private static void retrieveRepository() {
      try {
       theRepository = new JCO.Repository("saprep", theConnection);
      catch (Exception ex)
       System.out.println("failed to retrieve repository");
      public static JCO.Function getFunction(String name) {
        try {
             return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
        catch (Exception ex) {
         ex.printStackTrace();
          return null;
    Regards
    vijay

  • Execute operatingsystem commands from java classes?

    How can I execute operatingsystem commands from my java classes?
    So that I on a Linux box could i.e. execute "ls -l" etc.

    Also read this:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Running ssh command in a java application

    Hi there!
    I am trying to run a ssh command from a java application cause I need to store the result.
    Actually I can run this command in the cygwin shell so I need to open the shell and run the command, all trough java.
    so, what my process needs to do is:
    1) open the cmd
    2) run C:\cygwin\cygwin.bat
    3) execute the ssh command
    ssh -l fip-user ipdb fip 42704) print the result of the ssh command.
    Note that the cygwin opens in the same command line window and so will print it's result to the same process inputstream
    Message was edited by:
    RBervini

    Use "Runtime.getRuntime().exec()" to execute the SSH program,
    and you can then get the output of the SSH program
    via the getInputStream() method on the returned Process object.
    Note: there are many pitfalls with this. In particular, most people don't know
    they should create separate threads to drain the input/output pipes.
    See this excellent classic article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    on how to do it right.

  • How can i call a VB6 project from my java application using JNI

    hi
    can anyone tell me the procedure of calling a VB6 project from any java application using JNI
    if anyone does know then tell me the detail procedure of doing that. I know that i have to create a dll of that VB6 project then to call it from the java application.
    if anyone know that procedure of creating dll file of an existing VB6 project please reply
    please if anyone know then let me know

    Ahh, kind of a duplicate thread:
    http://forums.java.sun.com/thread.jspa?threadID=631642
    @OP. You could have clarified your original post and the relationship of your question to java. You did not need a new thread.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Launching a java application from another java application

    Hi,
    I'm facing an interesting challenge :-)
    Inside a Java application, I want to start another java application.
    Possible solutions in my list :
    1. Using jakarta commons launcher.
    2. Runtime.exec (make the code platform dependent).
    3. Starting the main method of the other app by create a new Thread inside the current app
    4. I know people did this by calling an ant target from the java application but I don't have
    any sample code, I appreciate any sample code for it.
    Thanks,
    Ali Salehi

    That is an iteresting challenge :)Don't be mean; he's polite, done some investigation and taken the trouble to be clear. The question, presumably, is "has anyone got a different solution or a preference as to which of these is the best?"
    In which case, my advice would be to say that invoking main in a separate thread is fundamentally different from Runtime.exec() because the former would run in the same JVM. Is this what you want? If one app has the other on its classpath then do they need to be separate apps? Could they be modules of a single app?

  • Execute DOS command from java application

    Hello,
    I want to execute a DOS command (MOVE, in order to move an image from a folder to an other) from a java application. How can I do this?
    Francesco

    Yes I have tested it and it is working but only when executing a bacth file. For instance:
    Runtime rt = Runtime.getRuntime();
    try{
         Process proc = rt.exec("move.bat");
    }catch(Exception ex){
         ex.printStackTrace();
    }and the command in move.bat is:
    move c:\\temp\\*.gif C:\\temp2
    You don't have to use double slashes in batch files, only in Java. But anyway it is working both ways.
    It is not working when you try to execute the command without the batch file:
    Process proc = rt.exec("move c:\\temp\\*.gif C:\\temp2"); -> this will not work.
    It should work. Try to execute another command to see what happens.

Maybe you are looking for

  • My iphone doesn't want to finish syncing in my laptop it just says step 6 of 6 waiting for changes to be applied

    My iPhone 5 doesn't want to finish syncing in itunes it just keep saying step 6 of 6 waiting for changes to be applied and I have tried like thousand times...

  • Invalid method "Save As" from Excel application object

    I have Windows 2000 and Excel 2002 installed on my machine. I down loaded "renamed Excel 2000 workbook.vi" from NI website. Relinked ref num to Excel application object but get the error of invalid method (Save As). Tried to relink invoke node to Sav

  • Apple iTV?

    I have a question for one or multiple Apple iEmployees:      Will there be an Apple iTV? I'm not talking about the TV Box Apple makes, but I'm talking about the Siri-powered television with a screen and speakers and all that. Apple is literally my li

  • MC$4 Vs FK10N

    HI Why there is difference between  MC$4 and FK10N Values. If I compare the debit amount from FK10N with Invoice amount figure from MC$4 for a prticular period there is huge difference. What is the basic fictionally between these two and If I want to

  • Adapter Engine Field missing --

    Hi All, I'm trying to create new Communication Channel in our QA system. I'm using 'Sender File Adapter'  But somehow When I choose below option, the last value (Adapter Engine) is blank. - Adapter type : Sender FILE   http://sap.com/xi/XI/System  SA