Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


mylib.JAR - where do I put "images"-folder ?

mylib.JAR - where do I put "images"-folder ?

mylib.JAR - where do I put "images"-folder ?

I have a small pluggable app that I want to distribute as jar-file.
I intend to put it in JRE/lib/ext, (nearly) everything works - only my icons (all in folder "images") will not be found.

I understand I have a PATH-problem. Maybe even different IDEs will handle that differently - I don't know. What do I do?
(I don't want to put the "raw" classes in the classes-folder, this of course works without problems).
Since it is my own code, I can change path settings in the program classes, no problem.

Any expert help available ?


RE: mylib.JAR - where do I put "images"-folder ?

It's not a choice. Classes must be in a directory with the package name (com.foo.MyClass must be in com/foo/MyClass.class) and your images must be in an accesible relative path.


RE: mylib.JAR - where do I put "images"-folder ?

Thanks, Dian - but

my helper.jar:
helper   -->  GlobalSymbols.class, .....
   displayhelper (not involved...)

The icons will be read in from a class GlobalSymbols that resides in helper. If I put the jar into jre/lib/ext I get no icons from the img-folder, I tried every possible combination changing the relative path when reading the icons into my icon-holding objects. It works when it is put in the classes-folder but not in jre/lib/ext, NO MATTER where I put the img folder.
I tried a couple of things. The only thing that works is to take the img-folder out of the jar and put it in a relative path  /classes/helper/img.
But then I cannot deliver just one jar-file!!!
Can the ressources like icons be delivered inside the jar ?
What does java do with non-java-files?
Does the jar behave like any other folder structure ?

(I guess it would be a ridiculous non-solution to use absolute paths...)


RE: mylib.JAR - where do I put "images"-folder ?

Yes, a jar behaves just like another structure added to the classpath. So if you include and img folder in the root of the jar, you can access files with the relative path img/, no matter wherever you put the jar.

Btw, how are you reading your images?


RE: mylib.JAR - where do I put "images"-folder ?


import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.*;

public class Resource extends JFrame {

    public Resource ()
        super ("super");
        JButton jp = new JButton (getImage ());
        getContentPane ().add (jp);
        setVisible (true);
    public static ImageIcon getImage () {
        URL url = Resource.class.getResource ("image.png" );
        if( url != null ) {
            return new ImageIcon( url );
        return null;

    public static void main (String[] args)
        System.out.println ("dat wird nix!");
        new Resource ();

don't visit my homepage: http://home.arcor.de/hirnstrom/minis/index.html

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close