This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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!
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.
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!
author and iconoclast
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.