Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • 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!

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

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

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

andyberlin2000 (Programmer)
3 Apr 11 15:11
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 ?



 
Diancecht (Programmer)
4 Apr 11 2:57
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.

Cheers,
Dian

andyberlin2000 (Programmer)
4 Apr 11 20:02
Thanks, Dian - but

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

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...)


 
Diancecht (Programmer)
5 Apr 11 2:49
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?

Cheers,
Dian

stefanwagner (Programmer)
6 Apr 11 19:33

CODE

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

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!

Back To Forum

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