views:

17

answers:

1

Hello all

Based on feedback from http://stackoverflow.com/questions/861500/url-to-load-resources-from-the-classpath-in-java i have changed my project, to include my image resources into Images.jar

My project setup is now

/program.jar
/Images.jar

In my code i load my images using

InputStream connectedImage = ClassLoader.getSystemResourceAsStream("images/logo.png");

My Eclipse setup is

/src/...
/images/logo.png

My problem

Eclipse cannot find the Systemresource based on that url. In order to get it to work, i have to

  1. Manually create Images.jar containing my image folder
  2. Add the Images.jar file to the Eclipse project

What I need

  1. How can i configure Eclipse so i can use the same code to load the image from either Images.Jar (if run from commandprompt) or from the images folder(if run from Eclipse)?

  2. Is there any way to make Eclipse include my /images/ folder when creating a runnable jar file of my program? Currently it does not include anything besides refereced jar files and source code.

+1  A: 

This is what I usually do:

  1. set the directory as source folder: right click -> Build Path -> Use as Source Folder
  2. change the structure of Images.jar so that the image files are on root (not under any directory)
  3. change the code to:

    InputStream connectedImage = 
        ClassLoader.getSystemResourceAsStream("logo.png");
    

UPDATE: with 1, you can export the images on the same jar as the classes

nanda