This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on images and packages

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic