InvocationTargetException for ClassLoaders.callStaticFunction Java Eclipse -
i have created program convert text xml using reversexsl api.
this program executed application calling static method (static int transformxsl).
i able execute , produce output running eclipse. however, when ran program (jar) using application stuck somewhere , couldnt find anything.
then, debugged "debug as...-> remote java application" in eclipse application , found "invocationtargetexception" @ classloaders.callstaticfunction.
below static method called application.
public class mytest4 {
public mytest4() { } public static int transformxsl(string deffile, string inputfile, string xslfile, string outputfile) { system.out.println("dheeraj's method called"); // start time filewriter fw=null; try { fw = new filewriter("d://countime.txt"); } catch (ioexception e1) { // todo auto-generated catch block e1.printstacktrace(); } bufferedwriter output=new bufferedwriter(fw); dateformat sd=new simpledateformat("yyyy-mm-dd hh:mm:ss.sss"); date dt= new date(); system.out.println("date calculated"); try { output.write("start time:"+sd.format(dt).tostring()); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } system.out.println(sd.format(dt)); filereader mydefreader=null, myxslreader=null; transformerfactory tf = transformerfactory.newinstance(); transformer t=null; fileinputstream instream = null; bytearrayoutputstream outstream = null; // step 1: //instantiate transformer specified def , xslt if (new file(deffile).canread()) { try { mydefreader = new filereader(deffile); system.out.println("definition file read"); } catch (filenotfoundexception e) { e.printstacktrace(); } } else mydefreader = null; if (new file(xslfile).canread()) try { myxslreader = new filereader(xslfile); system.out.println("xsl file read"); } catch (filenotfoundexception e) { e.printstacktrace(); } else myxslreader = null; try { t = tf.newtransformer(mydefreader, myxslreader); } catch (ioexception e) { e.printstacktrace(); } system.out.println("step 1: def , xslt transformation completed"); // step 2: // read input data try { instream = new fileinputstream(inputfile); } catch (filenotfoundexception e) { e.printstacktrace(); } outstream = new bytearrayoutputstream(); system.out.println("step 2: reading input file: completed"); // step 3: // transform input try { try (bufferedreader br = new bufferedreader(new filereader("d://2.txt"))) { string line = null; while ((line = br.readline()) != null) { system.out.println("content: "+line); } } system.out.println("file: "+inputfile.tostring()); system.out.println("\n content: \n"+ instream.tostring()); system.out.println("calling transform function"); t.transform(instream, outstream); system.out.println("transformation called"); outstream.close(); try(outputstream outputstream = new fileoutputstream(outputfile)) { outstream.writeto(outputstream); system.out.println("outstream generated; output file creating"); } system.out.println(outstream.tostring()); } catch (transformerexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (parserexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (parserconfigurationexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (factoryconfigurationerror e) { // todo auto-generated catch block e.printstacktrace(); } catch (transformerfactoryconfigurationerror e) { // todo auto-generated catch block e.printstacktrace(); } catch (javax.xml.transform.transformerexception e) { // todo auto-generated catch block e.printstacktrace(); } system.out.println("output file created"); // end time date dt2= new date(); system.out.println(sd.format(dt2)); system.out.println("end time:"+dt2.tostring()); try { output.append("end time:"+sd.format(dt2).tostring()); output.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } return 0; }
}
Comments
Post a Comment