Java: How to Read a Resource Inside a Jar

I was packaging my web service API as a Jar file.  The API has to access a WSDL xml file.

The file structure of the Jar looks like this:

Content of the webservice.jar file

If the class is also in the same jar file, you can simply read the file like this:

(in URL format)
final URL url =  this.getClass().getResource(”/webservice.asmx.xml”);

(in InputStream format)
final InputStream is = this.getClass().getResourceAsStream(”/webservice.asmx.xml”);

This entry was posted on Tuesday, February 3rd, 2009 at 10:20 pm and is filed under Java Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Java: How to Read a Resource Inside a Jar”

  1. Pleappilm Says:

    Thank you!

Leave a Reply