Loading Resources from an Imported JAR

The ClassLoader can be used to reference a resource in a JAR.  For example, if I packaged a JAR with a file called file.xml in the directory path/in/JAR, I would use the code below.

this.getClass().getClassLoader().getResource(“path/in/JAR/file.xml”);

If you need to reference other files, it may be smart to use a Java Enum to store these locations for better organization.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s