aspose file tools*
The moose likes Beginning Java and the fly likes Question on images and packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Question on images and packages" Watch "Question on images and packages" New topic
Author

Question on images and packages

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I am trying to figure out a way to set up my packages
to contain one images folder, with all images in it for different
classes.
I was told that in order for the line-

to work, the image has to be in the same package or a sub package of the class that is being used to load it.
Which I think I understand.
If I have a package com/storekraft/est with classes in it that use images , the images must be in com/storekraft/est or com/storekraft/est/images Correct?
I have numerous folders under the package com/storekraft where some of the classes in different folders use the same image as another one.
For instance, I have classes in com/storekraft/est and a class in com/storekraft/bom that use the same image.
So, am I going to have to have that image in both of those packages? If so, that means I have two copies of the image.
How can I only keep one copy of the image, so both classes can use it?
Thanks for any help!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

What you say is true of "relative paths". You can use "absolute paths" too.
[code]
URL url = LoadImageExample.class.getResource("/com/storecraft/est/images/watermark.jpg");
[/com]
(Note the leading slash). Using this syntax, any class will be able to find the image.


[Jess in Action][AskingGoodQuestions]
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the help with my image question.
I have come across another question, that has to do more with jarring files.
I have the jar file (jt400.jar) for our database as well as the class files for the application I want to run. I have jarred up all of my class files, and put the jt400.jar file in there with them.
But when I run the main jar file, it can't find the database driver classes??
Do I have to extract the contents of jt400.jar and then put them in my main jar file?
If I don't need to extract the contents of jt400.jar, what do I need to do recognize the database classes?
Thanks again!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Generally in a server environment, people keep jar files separate; all the necessary jars go on the CLASSPATH or in the appropriate server library directory, or JAVA_HOME/jre/lib/ext. But if you need to make a single, self-contained, clickable, executable jar, then yes, you would need to extract all the contents of the one and put it into the other.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
On the subject of packaging and using a JAR within an executable JAR, you might find teh latter part of my creating an executable JAR thread to be useful where I describe the steps to do such a thing.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on images and packages