Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2008
    Rep Power

    Red face excecuting a jar file by calling a java class

    Using the library servingxml I have created a xml resource file that will convert a flatfile to xml. now in the command prompt if I run the following command I will get the output.

    java -jar c:\WPs\servingxml-0.9.5\target\servingxml\servingxml.jar -r resources-books.xml -i data\\books.txt -o output\\books.xml books

    now I have written a java class that will execute this command. The program compiles and runs fine, but unfortunately the expected command does not gets executed.

    So can any one help me telling how to execute it?

    the java class I have written is


    import java.util.*;
    import java.lang.*;

    class time_diff_new
    public static void main(String[] av)

    String[] arguments = new String[10];

    arguments[0] = "java";
    arguments[1] = "-jar";
    arguments[2] = "C:/WPS/servingxml-0.9.5/target/servingxml/servingxml.jar";
    arguments[3] = "-r";
    arguments[4] = "customer_resources.xml";
    arguments[5] = "-i";
    arguments[6] = "data/customer_input.txt";
    arguments[7] = "-o";
    arguments[8] = "output/customer_output.xml";
    arguments[9] = "customers";

    String[] newargument = new String[1];

    // newargument[0]=arguments[0]+" "+arguments[1]+" "+arguments[2]+" "+arguments[3]+" "+arguments[4]+" "+arguments[5]+" "+arguments[6]+" "+arguments[7]+" "+arguments[8]+" "+arguments[9];
    System.out.println("the values of arguements " +newargument[0]);

    Calendar now = Calendar.getInstance();
    long diff = 0;
    long t1 = 0;
    long t2 = 0;
    t1 = now.getTimeInMillis();



    //Process proc = Runtime.getRuntime().exec(cmd);

    /*BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
    String message = "SC";
    writer.write(message, 0, 1);

    catch(Exception e)
    System.out.println("error::" + e);
    now = Calendar.getInstance();
    t2 = now.getTimeInMillis();
    diff = t2-t1;
    System.out.println("Time1 is :: "+t1+"\nTime2 is :: "+t2+"\nDifference is:: " + diff);

    } this statement is the command line implementation of ServingXML.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    Did you get any error message. Just think about that lol, since you are using an external package, or a non-standard library no one can run and test your code. Even it has, I don't think anyone wants to run this code. So better to provide full details about your question.

    Java Code:
    //Process proc = Runtime.getRuntime().exec(cmd);
    In the above line of code, where you define cmd in your class. I cannot see any initialization.

Similar Threads

  1. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  2. Inner Class and Calling Values
    By a45b22chp in forum New To Java
    Replies: 3
    Last Post: 04-25-2008, 08:48 PM
  3. Calling method from another class
    By asahli in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 06:24 PM
  4. calling a java class from html
    By Ed in forum Advanced Java
    Replies: 1
    Last Post: 07-08-2007, 12:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts