Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

andyberlin2000

Programmer
May 12, 2004
18
0
0
DE
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 ?



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


 
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
 
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:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top