Thread: [javaCompiler-users] compiles and executes but throws java exception --help
Status: Beta
Brought to you by:
soapy
From: Steven B. <dud...@gm...> - 2007-02-13 10:02:03
|
hi i have used JNC to compile a java app that does some xml parsing and transformation. my app references the javax.xml.parsers and javax.xml.transform, nothing fancy in there. it compiles fine but whenever i try to instantiate a SAXTransformerFactory in my java code, i get the following error (Trs_Main is the .exe) Exception in thread "main" javax.xml.transform.TransformerFactoryConfigurationError: gnu.xml.transform.TransformerFactoryImpl at java.lang.VMThrowable.fillInStackTrace(Trs_Main.exe) at java.lang.Throwable.<init>(Trs_Main.exe) at javax.xml.transform.TransformerFactory.newInstance(Trs_Main.exe) // i guess this is where the error comes from at asy.TrsToXML.split(Trs_Main.exe) also when i try to instantiate a SAXParserFactory object using "SAXParserFactory factory=SAXParserFactory.newInstance();" i get another error, probably related : Exception in thread "main" java.lang.NoClassDefFoundError: gnu.xml.stream.SAXParserFactory at javax.xml.parsers.SAXParserFactory.newInstance(Trs_Main.exe) im using jdk1.4.12 does this occur because JNC supports gnu's and not sun's SAX implementation? please tell me what to do, do i have to use gnu's SAX in order to get it to work? and if so please tell me where to find it. Thank you. Steven |
From: Marco T. <mt...@gm...> - 2007-02-13 10:26:05
|
Steven Blade wrote: > hi > i have used JNC to compile a java app that does some xml parsing and > transformation. > my app references the javax.xml.parsers and javax.xml.transform, nothing > fancy in there. > it compiles fine but whenever i try to instantiate a > SAXTransformerFactory in my java code, i get the following error > (Trs_Main is the .exe) > Exception in thread "main" > javax.xml.transform.TransformerFactoryConfigurationError: > gnu.xml.transform.TransformerFactoryImpl > at java.lang.VMThrowable.fillInStackTrace(Trs_Main.exe) > at java.lang.Throwable .<init>(Trs_Main.exe) > at javax.xml.transform.TransformerFactory.newInstance(Trs_Main.exe) // i > guess this is where the error comes from > at asy.TrsToXML.split(Trs_Main.exe) > > also when i try to instantiate a SAXParserFactory object using > "SAXParserFactory factory=SAXParserFactory.newInstance();" > i get another error, probably related : > Exception in thread "main" java.lang.NoClassDefFoundError : > gnu.xml.stream.SAXParserFactory > at javax.xml.parsers.SAXParserFactory.newInstance(Trs_Main.exe) > > im using jdk1.4.12 > > does this occur because JNC supports gnu's and not sun's SAX implementation? > please tell me what to do, do i have to use gnu's SAX in order to get it > to work? > and if so please tell me where to find it. Can you please provide two meaningful minimal examples for the described two cases? I never got around to test XML myself, so that would be a help... Marco > Thank you. > Steven > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > ------------------------------------------------------------------------ > > _______________________________________________ > javaCompiler-users mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/javacompiler-users |
From: Steven B. <dud...@gm...> - 2007-02-14 06:34:14
|
On 2/13/07, Marco Trudel <mt...@gm...> wrote: > > Sorry, forgot to CC you since you're not on the mailinglist... So here > my forwarded answer... > > Steven Blade wrote: > > hi > > i have used JNC to compile a java app that does some xml parsing and > > transformation. > > my app references the javax.xml.parsers and javax.xml.transform, nothing > > fancy in there. > > it compiles fine but whenever i try to instantiate a > > SAXTransformerFactory in my java code, i get the following error > > (Trs_Main is the .exe) > > Exception in thread "main" > > javax.xml.transform.TransformerFactoryConfigurationError: > > gnu.xml.transform.TransformerFactoryImpl > > at java.lang.VMThrowable.fillInStackTrace(Trs_Main.exe) > > at java.lang.Throwable .<init>(Trs_Main.exe) > > at javax.xml.transform.TransformerFactory.newInstance(Trs_Main.exe) // i > > guess this is where the error comes from > > at asy.TrsToXML.split(Trs_Main.exe) > > > > also when i try to instantiate a SAXParserFactory object using > > "SAXParserFactory factory=SAXParserFactory.newInstance();" > > i get another error, probably related : > > Exception in thread "main" java.lang.NoClassDefFoundError : > > gnu.xml.stream.SAXParserFactory > > at javax.xml.parsers.SAXParserFactory.newInstance(Trs_Main.exe) > > > > im using jdk1.4.12 > > > > does this occur because JNC supports gnu's and not sun's SAX > implementation? > > please tell me what to do, do i have to use gnu's SAX in order to get it > > to work? > > and if so please tell me where to find it. > > Can you please provide two meaningful minimal examples for the described > two cases? I never got around to test XML myself, so that would be a > help... > > > Marco > > > Thank you. > > Steven > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > Using Tomcat but need to do more? Need to support web services, > security? > > Get stuff done quickly with pre-integrated technology to make your job > easier. > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > javaCompiler-users mailing list > > jav...@li... > > https://lists.sourceforge.net/lists/listinfo/javacompiler-users > > > public void trsToXml(String ofile) { SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); //the exception points to this line try{ FileWriter fw=new FileWriter(ofile); PrintWriter pw=new PrintWriter(fw,true); StreamResult stream=new StreamResult(pw); handler=factory.newTransformerHandler(); Transformer trans=handler.getTransformer(); trans.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"trs_xml.dtd"); trans.setOutputProperty(OutputKeys.INDENT,"yes"); handler.setResult(stream); handler.startDocument(); AttributesImpl atts=new AttributesImpl(); handler.startElement("", "", "test", atts); atts.clear(); handler.startElement("", "", "foo", atts); handler.characters(new char[]{'a','b','c'}, 0, 3); handler.endElement("", "", "foo"); handler.endElement("", "", "test"); handler.endDocument(); pw.flush(); pw.close(); }catch(Exception _){_.printStackTrace();} this one throws the first exception } public void xmlToTrs(File sfile,String oFileName) { PrintWriter pWriter=null; try{ SAXParserFactory factory=SAXParserFactory.newInstance(); // the exception points to this line factory.setValidating(true); SAXParser parser=factory.newSAXParser(); boolean proceed=true; File trs=new File(oFileName); if(trs.isFile() && trs.exists()) { System.out.println("the file \""+oFileName+"\" already exists\nDo you wish to overwrite it ? Y/N\n"); BufferedReader input=new BufferedReader(new InputStreamReader(System.in )); proceed=input.readLine().equalsIgnoreCase("y"); } if(proceed) { parser.parse(sfile, new DefaultHandler()); pWriter=new PrintWriter(new FileWriter(trs),true); pWriter.write(sHeading.toString ()+sGeneral.toString()+sItems.toString()); pWriter.flush(); } } catch(Exception _){_.printStackTrace();} finally{if(pWriter!=null) pWriter.close();} } and this one the second -- |
From: Marco T. <mt...@gm...> - 2007-02-14 13:45:02
|
Steven Blade wrote: > <snip> > > public void trsToXml(String ofile) > { > SAXTransformerFactory > factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); > //the exception points to this line > try{ > FileWriter fw=new FileWriter(ofile); > PrintWriter pw=new PrintWriter(fw,true); > StreamResult stream=new StreamResult(pw); > handler=factory.newTransformerHandler(); > Transformer trans=handler.getTransformer(); > trans.setOutputProperty (OutputKeys.ENCODING,"ISO-8859-1"); > trans.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,"trs_xml.dtd"); > trans.setOutputProperty(OutputKeys.INDENT,"yes"); > handler.setResult(stream); > handler.startDocument(); > AttributesImpl atts=new AttributesImpl(); > handler.startElement("", "", "test", atts); > atts.clear(); > handler.startElement("", "", "foo", atts); > handler.characters(new char[]{'a','b','c'}, 0, 3); > handler.endElement("", "", "foo"); > handler.endElement("", "", "test"); > handler.endDocument(); > pw.flush(); > pw.close(); > }catch(Exception _){_.printStackTrace();} > this one throws the first exception > } > public void xmlToTrs(File sfile,String oFileName) > { > PrintWriter pWriter=null; > try{ > SAXParserFactory factory=SAXParserFactory.newInstance(); // the > exception points to this line > factory.setValidating(true); > SAXParser parser=factory.newSAXParser(); > boolean proceed=true; > File trs=new File(oFileName); > if(trs.isFile() && trs.exists()) > { > System.out.println("the file \""+oFileName+"\" already exists\nDo > you wish to overwrite it ? Y/N\n"); > BufferedReader input=new BufferedReader(new > InputStreamReader(System.in <http://System.in>)); > proceed=input.readLine().equalsIgnoreCase("y"); > } > if(proceed) > { > parser.parse (sfile, new DefaultHandler()); > pWriter=new PrintWriter(new FileWriter(trs),true); > pWriter.write(sHeading.toString()+sGeneral.toString()+sItems.toString()); > pWriter.flush(); > } > } > catch(Exception _){_.printStackTrace();} > finally{if(pWriter!=null) pWriter.close();} > } > and this one the second Unfortunately I can't do much with them. What I meant was a self-containing minimal example that I can run. E.g. some stupid parsing or transforming. A XML HelloWorld if you like... So, I just tested the: SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); And I need this to get it working: static { gnu.xml.dom.ls.SAXEventSink.class.getName(); gnu.xml.transform.TransformerFactoryImpl.class.getName(); gnu.xml.xpath.XPathFactoryImpl.class.getName(); org.xml.sax.ContentHandler.class.getName(); } Please read the very small "Step 1 of 4: Source" part in the manual to understand why this is necessary. Maybe you need more of them for other XML stuff too... I'd still appreciate a minimal XML HelloWorld if you have time. Attached and not inlined if possible :-) Hope it helps... Marco |
From: Marco T. <mt...@gm...> - 2007-02-15 08:02:11
Attachments:
XmlLoader.java
|
Please always do "reply all", else we loose the mailinglist... Steven Blade wrote: > ok sure thing but please show me where to use the static block of code ok. Thanks for the sample. Just put that code in an own class (as the attached XmlLoader.java) and add this class to the JNC compilation source. This will ensure that the needed objects are pulled into the binary. You do not have to change your source. > did it work both ways with you reading and transforming xml ? Reading works, writing (transforming) fails. I'll create a bugreport (it's probably a GNU classpath bug) and hope that the fix will be in JNC 1.2. > one more thing does that mean i have to use gnu's jar instead of java's ? No, you only have to ensure that your binary contains the xml stuff. This is done with the static initializer since it references the xml stuff and thus ld - the linker - will add them. Marco > import java.io.BufferedReader; > import java.io.File; > import java.io.InputStreamReader; > > import javax.xml.parsers.SAXParser; > import javax.xml.parsers.SAXParserFactory; > import javax.xml.transform.OutputKeys; > import javax.xml.transform.Transformer; > import javax.xml.transform.sax.SAXTransformerFactory; > import javax.xml.transform.sax.TransformerHandler; > import javax.xml.transform.stream.StreamResult; > > import org.xml.sax.Attributes; > import org.xml.sax.SAXException; > import org.xml.sax.helpers.AttributesImpl; > import org.xml.sax.helpers.DefaultHandler; > > > public class Foo extends DefaultHandler{ > > /** > * @param args > */ > private static File file; > private static String contents; > private static Foo f=new Foo(); > public static void main(String[] args) { > // TODO Auto-generated method stub > System.out.print("enter location of xml file to read "); > BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); > try > { > String sfile=input.readLine(); > file=new File(sfile); > readXml(); > System.out.print(contents); > writeXml(); > }catch(Exception _){_.printStackTrace();} > } > private static void writeXml() > { > SAXTransformerFactory factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); > try{ > StreamResult stream=new StreamResult(System.out); > TransformerHandler handler=factory.newTransformerHandler(); > Transformer trans=handler.getTransformer(); > trans.setOutputProperty (OutputKeys.ENCODING,"ISO-8859-1"); > trans.setOutputProperty(OutputKeys.INDENT,"yes"); > handler.setResult(stream); > handler.startDocument(); > AttributesImpl atts=new AttributesImpl(); > handler.startElement("", "", "test", atts); > atts.clear(); > handler.startElement("", "", "foo", atts); > handler.characters(new char[]{'a','b','c'}, 0, 3); > handler.endElement("", "", "foo"); > handler.endElement("", "", "test"); > handler.endDocument(); > }catch(Exception _){_.printStackTrace();} > } > > private static void readXml() > { > System.out.println("reading xml..."); > try{ > SAXParserFactory factory=SAXParserFactory.newInstance(); // the exception points to this line > factory.setValidating(false); > SAXParser parser=factory.newSAXParser(); > parser.parse (file, f.new OwnHandler()); > } > catch(Exception _){_.printStackTrace();} > } > > private class OwnHandler extends DefaultHandler{ > > public void startElement(String namespaceURI, > String sName, > String qName, > Attributes attrs) throws SAXException{ > contents+="<"+qName+">"; > } > public void endElement(String uri, String localName, String qName) throws SAXException{ > contents+="<"+qName+"/>"; > } > public void characters(char[] buf,int offset,int length)throws SAXException{ > contents+=new String(buf,offset,length); > } > } > } > > > > > ------------------------------------------------------------------------ > > <?xml version=1.0 encoding=UTF-8?> > <test> > <line>testing java native compiler</line> > </test> |
From: Steven B. <dud...@gm...> - 2007-02-15 12:53:06
|
>package ch.mtSystems.jnc.model.utilities; *and the package declaration should be the same as you gave me right ?i just create this class in my project in this package after adding the gnu jar and that's it.* *but no support for writing xml yet , oh well.* *Maroc thanks alot for your time man, if you have any other suggestions please tell me .* *Thanks* On 2/15/07, Marco Trudel <mt...@gm...> wrote: > > Please always do "reply all", else we loose the mailinglist... > > > Steven Blade wrote: > > ok sure thing but please show me where to use the static block of code > ok. > > Thanks for the sample. Just put that code in an own class (as the > attached XmlLoader.java) and add this class to the JNC compilation > source. This will ensure that the needed objects are pulled into the > binary. > You do not have to change your source. > > > > did it work both ways with you reading and transforming xml ? > > Reading works, writing (transforming) fails. I'll create a bugreport > (it's probably a GNU classpath bug) and hope that the fix will be in JNC > 1.2. > > > one more thing does that mean i have to use gnu's jar instead of java's > ? > > No, you only have to ensure that your binary contains the xml stuff. > This is done with the static initializer since it references the xml > stuff and thus ld - the linker - will add them. > > > Marco > > > > import java.io.BufferedReader; > > import java.io.File; > > import java.io.InputStreamReader; > > > > import javax.xml.parsers.SAXParser; > > import javax.xml.parsers.SAXParserFactory; > > import javax.xml.transform.OutputKeys; > > import javax.xml.transform.Transformer; > > import javax.xml.transform.sax.SAXTransformerFactory; > > import javax.xml.transform.sax.TransformerHandler; > > import javax.xml.transform.stream.StreamResult; > > > > import org.xml.sax.Attributes; > > import org.xml.sax.SAXException; > > import org.xml.sax.helpers.AttributesImpl; > > import org.xml.sax.helpers.DefaultHandler; > > > > > > public class Foo extends DefaultHandler{ > > > > /** > > * @param args > > */ > > private static File file; > > private static String contents; > > private static Foo f=new Foo(); > > public static void main(String[] args) { > > // TODO Auto-generated method stub > > System.out.print("enter location of xml file to read "); > > BufferedReader input=new BufferedReader(new > InputStreamReader(System.in)); > > try > > { > > String sfile=input.readLine(); > > file=new File(sfile); > > readXml(); > > System.out.print(contents); > > writeXml(); > > }catch(Exception _){_.printStackTrace();} > > } > > private static void writeXml() > > { > > SAXTransformerFactory > factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); > > try{ > > StreamResult stream=new StreamResult(System.out); > > TransformerHandler handler=factory.newTransformerHandler(); > > Transformer trans=handler.getTransformer(); > > trans.setOutputProperty (OutputKeys.ENCODING,"ISO-8859-1"); > > trans.setOutputProperty(OutputKeys.INDENT,"yes"); > > handler.setResult(stream); > > handler.startDocument(); > > AttributesImpl atts=new AttributesImpl(); > > handler.startElement("", "", "test", atts); > > atts.clear(); > > handler.startElement("", "", "foo", atts); > > handler.characters(new char[]{'a','b','c'}, 0, 3); > > handler.endElement("", "", "foo"); > > handler.endElement("", "", "test"); > > handler.endDocument(); > > }catch(Exception _){_.printStackTrace();} > > } > > > > private static void readXml() > > { > > System.out.println("reading xml..."); > > try{ > > SAXParserFactory factory=SAXParserFactory.newInstance(); // the > exception points to this line > > factory.setValidating(false); > > SAXParser parser=factory.newSAXParser(); > > parser.parse (file, f.new OwnHandler()); > > } > > catch(Exception _){_.printStackTrace();} > > } > > > > private class OwnHandler extends DefaultHandler{ > > > > public void startElement(String namespaceURI, > > String sName, > > String qName, > > Attributes attrs) throws SAXException{ > > contents+="<"+qName+">"; > > } > > public void endElement(String uri, String localName, String > qName) throws SAXException{ > > contents+="<"+qName+"/>"; > > } > > public void characters(char[] buf,int offset,int length)throws > SAXException{ > > contents+=new String(buf,offset,length); > > } > > } > > } > > > > > > > > > > ------------------------------------------------------------------------ > > > > <?xml version=1.0 encoding=UTF-8?> > > <test> > > <line>testing java native compiler</line> > > </test> > > > package ch.mtSystems.jnc.model.utilities; > > public class XmlLoader > { > static > { > gnu.xml.dom.ls.SAXEventSink.class.getName(); > gnu.xml.transform.TransformerFactoryImpl.class.getName(); > gnu.xml.xpath.XPathFactoryImpl.class.getName(); > org.xml.sax.ContentHandler.class.getName(); > gnu.xml.stream.SAXParserFactory.class.getName(); > } > } > > -- kc |
From: Marco T. <mt...@gm...> - 2007-02-15 13:01:51
|
Steven Blade wrote: > >package ch.mtSystems.jnc.model.utilities; > *and the package declaration should be the same as you gave me right ? No. It doesn't matter in which class or package it is. The only thing that matters is that the compiler runs into statements like: gnu.xml.dom.ls.SAXEventSink.class.getName(); So that he knows to include gnu.xml.dom.ls.SAXEventSink because you need it. Did you read the manual part about that I told you? It's all explained in there... > i > just create this class in my project in this package after adding the > gnu jar and that's it.* You don't have to do that. Just put the class I gave you or one that you made yourself somewhere on your drive and add it only to the compilation. Don't add a jar to the project or that file to the project when you're developing. It's not necessary and not needed. It's only needed for native compilation and only a hint to the compiler. You won't need it ever... > *but no support for writing xml yet , oh well.* Definitely not the way you did in your sample applications. There probably are hundreds of other ways that will work... > *Maroc thanks alot for your time man, if you have any other suggestions > please tell me .* You could always hire me to fix it or find another solution. Of course that would cost something... Contact me in private if you're interested... Marco > *Thanks* > > On 2/15/07, *Marco Trudel* <mt...@gm... <mailto:mt...@gm...>> wrote: > > Please always do "reply all", else we loose the mailinglist... > > > Steven Blade wrote: > > ok sure thing but please show me where to use the static block of > code ok. > > Thanks for the sample. Just put that code in an own class (as the > attached XmlLoader.java) and add this class to the JNC compilation > source. This will ensure that the needed objects are pulled into the > binary. > You do not have to change your source. > > > > did it work both ways with you reading and transforming xml ? > > Reading works, writing (transforming) fails. I'll create a bugreport > (it's probably a GNU classpath bug) and hope that the fix will be in JNC > 1.2. > > > one more thing does that mean i have to use gnu's jar instead of > java's ? > > No, you only have to ensure that your binary contains the xml stuff. > This is done with the static initializer since it references the xml > stuff and thus ld - the linker - will add them. > > > Marco > > > > import java.io.BufferedReader; > > import java.io.File; > > import java.io.InputStreamReader; > > > > import javax.xml.parsers.SAXParser; > > import javax.xml.parsers.SAXParserFactory; > > import javax.xml.transform.OutputKeys; > > import javax.xml.transform.Transformer ; > > import javax.xml.transform.sax.SAXTransformerFactory; > > import javax.xml.transform.sax.TransformerHandler; > > import javax.xml.transform.stream.StreamResult; > > > > import org.xml.sax.Attributes ; > > import org.xml.sax.SAXException; > > import org.xml.sax.helpers.AttributesImpl; > > import org.xml.sax.helpers.DefaultHandler; > > > > > > public class Foo extends DefaultHandler{ > > > > /** > > * @param args > > */ > > private static File file; > > private static String contents; > > private static Foo f=new Foo(); > > public static void main(String[] args) { > > // TODO Auto-generated method stub > > System.out.print("enter location of xml file to > read "); > > BufferedReader input=new BufferedReader(new > InputStreamReader( System.in <http://System.in>)); > > try > > { > > String sfile=input.readLine(); > > file=new File(sfile); > > readXml(); > > System.out.print(contents); > > writeXml(); > > }catch(Exception _){_.printStackTrace();} > > } > > private static void writeXml() > > { > > SAXTransformerFactory > factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); > > try{ > > StreamResult stream=new StreamResult(System.out); > > TransformerHandler handler= > factory.newTransformerHandler(); > > Transformer trans=handler.getTransformer(); > > trans.setOutputProperty (OutputKeys.ENCODING,"ISO-8859-1"); > > trans.setOutputProperty (OutputKeys.INDENT,"yes"); > > handler.setResult(stream); > > handler.startDocument(); > > AttributesImpl atts=new AttributesImpl(); > > handler.startElement("", "", "test", atts); > > atts.clear(); > > handler.startElement("", "", "foo", atts); > > handler.characters(new char[]{'a','b','c'}, 0, 3); > > handler.endElement("", "", "foo"); > > handler.endElement("", "", "test"); > > handler.endDocument(); > > }catch(Exception _){_.printStackTrace();} > > } > > > > private static void readXml() > > { > > System.out.println("reading xml..."); > > try{ > > SAXParserFactory factory= > SAXParserFactory.newInstance(); // the exception points to this line > > factory.setValidating(false); > > SAXParser parser=factory.newSAXParser(); > > parser.parse (file, f.new OwnHandler()); > > } > > catch(Exception _){_.printStackTrace();} > > } > > > > private class OwnHandler extends DefaultHandler{ > > > > public void startElement(String namespaceURI, > > String sName, > > String qName, > > Attributes attrs) throws SAXException{ > > contents+="<"+qName+">"; > > } > > public void endElement(String uri, String localName, > String qName) throws SAXException{ > > contents+="<"+qName+"/>"; > > } > > public void characters(char[] buf,int offset,int > length)throws SAXException{ > > contents+=new String(buf,offset,length); > > } > > } > > } > > > > > > > > > > > ------------------------------------------------------------------------ > > > > <?xml version=1.0 encoding=UTF-8?> > > <test> > > <line>testing java native compiler</line> > > </test> > > > package ch.mtSystems.jnc.model.utilities; > > public class XmlLoader > { > static > { > gnu.xml.dom.ls.SAXEventSink.class.getName(); > gnu.xml.transform.TransformerFactoryImpl.class.getName(); > gnu.xml.xpath.XPathFactoryImpl.class.getName(); > org.xml.sax.ContentHandler.class.getName(); > gnu.xml.stream.SAXParserFactory.class.getName (); > } > } > > > > > -- > kc |
From: Marco T. <mt...@gm...> - 2007-02-20 13:04:05
|
Steven Blade wrote: > >package ch.mtSystems.jnc.model.utilities; > *and the package declaration should be the same as you gave me right ?i > just create this class in my project in this package after adding the > gnu jar and that's it.* > *but no support for writing xml yet , oh well.* The bug why your XML writing failed was fixed in GNU classpath and I imported it into GCJ. So it will work with the next version of JNC... Marco > *Maroc thanks alot for your time man, if you have any other suggestions > please tell me .* > *Thanks* > > On 2/15/07, *Marco Trudel* <mt...@gm... <mailto:mt...@gm...>> wrote: > > Please always do "reply all", else we loose the mailinglist... > > > Steven Blade wrote: > > ok sure thing but please show me where to use the static block of > code ok. > > Thanks for the sample. Just put that code in an own class (as the > attached XmlLoader.java) and add this class to the JNC compilation > source. This will ensure that the needed objects are pulled into the > binary. > You do not have to change your source. > > > > did it work both ways with you reading and transforming xml ? > > Reading works, writing (transforming) fails. I'll create a bugreport > (it's probably a GNU classpath bug) and hope that the fix will be in JNC > 1.2. > > > one more thing does that mean i have to use gnu's jar instead of > java's ? > > No, you only have to ensure that your binary contains the xml stuff. > This is done with the static initializer since it references the xml > stuff and thus ld - the linker - will add them. > > > Marco > > > > import java.io.BufferedReader; > > import java.io.File; > > import java.io.InputStreamReader; > > > > import javax.xml.parsers.SAXParser; > > import javax.xml.parsers.SAXParserFactory; > > import javax.xml.transform.OutputKeys; > > import javax.xml.transform.Transformer ; > > import javax.xml.transform.sax.SAXTransformerFactory; > > import javax.xml.transform.sax.TransformerHandler; > > import javax.xml.transform.stream.StreamResult; > > > > import org.xml.sax.Attributes ; > > import org.xml.sax.SAXException; > > import org.xml.sax.helpers.AttributesImpl; > > import org.xml.sax.helpers.DefaultHandler; > > > > > > public class Foo extends DefaultHandler{ > > > > /** > > * @param args > > */ > > private static File file; > > private static String contents; > > private static Foo f=new Foo(); > > public static void main(String[] args) { > > // TODO Auto-generated method stub > > System.out.print("enter location of xml file to > read "); > > BufferedReader input=new BufferedReader(new > InputStreamReader( System.in <http://System.in>)); > > try > > { > > String sfile=input.readLine(); > > file=new File(sfile); > > readXml(); > > System.out.print(contents); > > writeXml(); > > }catch(Exception _){_.printStackTrace();} > > } > > private static void writeXml() > > { > > SAXTransformerFactory > factory=(SAXTransformerFactory)SAXTransformerFactory.newInstance(); > > try{ > > StreamResult stream=new StreamResult(System.out); > > TransformerHandler handler= > factory.newTransformerHandler(); > > Transformer trans=handler.getTransformer(); > > trans.setOutputProperty (OutputKeys.ENCODING,"ISO-8859-1"); > > trans.setOutputProperty (OutputKeys.INDENT,"yes"); > > handler.setResult(stream); > > handler.startDocument(); > > AttributesImpl atts=new AttributesImpl(); > > handler.startElement("", "", "test", atts); > > atts.clear(); > > handler.startElement("", "", "foo", atts); > > handler.characters(new char[]{'a','b','c'}, 0, 3); > > handler.endElement("", "", "foo"); > > handler.endElement("", "", "test"); > > handler.endDocument(); > > }catch(Exception _){_.printStackTrace();} > > } > > > > private static void readXml() > > { > > System.out.println("reading xml..."); > > try{ > > SAXParserFactory factory= > SAXParserFactory.newInstance(); // the exception points to this line > > factory.setValidating(false); > > SAXParser parser=factory.newSAXParser(); > > parser.parse (file, f.new OwnHandler()); > > } > > catch(Exception _){_.printStackTrace();} > > } > > > > private class OwnHandler extends DefaultHandler{ > > > > public void startElement(String namespaceURI, > > String sName, > > String qName, > > Attributes attrs) throws SAXException{ > > contents+="<"+qName+">"; > > } > > public void endElement(String uri, String localName, > String qName) throws SAXException{ > > contents+="<"+qName+"/>"; > > } > > public void characters(char[] buf,int offset,int > length)throws SAXException{ > > contents+=new String(buf,offset,length); > > } > > } > > } > > > > > > > > > > > ------------------------------------------------------------------------ > > > > <?xml version=1.0 encoding=UTF-8?> > > <test> > > <line>testing java native compiler</line> > > </test> > > > package ch.mtSystems.jnc.model.utilities; > > public class XmlLoader > { > static > { > gnu.xml.dom.ls.SAXEventSink.class.getName(); > gnu.xml.transform.TransformerFactoryImpl.class.getName(); > gnu.xml.xpath.XPathFactoryImpl.class.getName(); > org.xml.sax.ContentHandler.class.getName(); > gnu.xml.stream.SAXParserFactory.class.getName (); > } > } > > > > > -- > kc |