dcsimg
Reading xml file bundled inside a jar file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, March 10, 2004 09:38 PM

Hi, I want to read and parse an xml file which has to be bundled into a jar along with the class file. When i am putting the xml file outside the jar it is working but when put inside the jar, the class is not able to access it it is giving the following error Exception in thread "main" java.lang.ClassFormatError: Test (Bad magic number) I used the following piece of code .... java.net.URL url = getClass().getResource("test.xml"); String file= url.getPath(); ...... ..... try{ saxParser.parse( new File(file), handler); .... pls help thanx in advance Binny    More>>

Hi,
I want to read and parse an xml file which has to be bundled into a jar along with the class file. When i am putting the xml file outside the jar it is working but when put inside the jar, the class is not able to access it
it is giving the following error

Exception in thread "main" java.lang.ClassFormatError: Test (Bad magic number)


I used the following piece of code

....
java.net.URL url = getClass().getResource("test.xml");
String file= url.getPath();

......
.....
try{
saxParser.parse( new File(file), handler);
....

pls help
thanx in advance
Binny

   <<Less

Re: Reading xml file bundled inside a jar file

Posted By:   Anjan_Bacchu  
Posted On:   Wednesday, March 10, 2004 11:09 PM

hi binny,



I believe that your JAR file's class-path is not properly set. Follow the link below to get an example of specifying the class-path for the resources(including .CLASS files)

http://www.rgagnon.com/javadetails/java-0166.html


BR,

~A
About | Sitemap | Contact