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 docs.api.com.servingxml.app.consoleapp.*;
import java.util.*;
import java.lang.*;
import java.io.*;
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();
try
{
ConsoleApp.main(newargument[0]);
//Process proc = Runtime.getRuntime().exec(cmd);
/*BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
String message = "SC";
writer.write(message, 0, 1);
System.out.println(\n\t"waiting...");*/
//proc.waitFor();
}
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);
}
}
com.servingxml.app.consoleapp. this statement is the command line implementation of ServingXML.