Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null ImageIcon from getResource in jar

 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code snippet:

From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.

My class is in "durz.images"; I tried it once with the images in that same directory and just specifying iconName; I tried moving the images to their own "images" subdirectory and specifying "images/" + iconName.

I have verified that the jar file contains the images in the directory path, relative to the root of the jar file, that they're supposed to be in. I did that once when they were in the same directory as the class, and again after I moved them to their own images directory off the directory the class was in.

I am aware that the "/" at the front of the getResource() string parameter means "absolute path within the jar", and without the "/" the path is relative to the path the class is in, in the jar.

Can anyone see what I'm doing wrong here?

rc
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ralph. Can you post an SSCCE?
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ralph Cook wrote:From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.


How, exactly, did you run the program outside of the IDE? Command line? what command? or did you just double-click an executable jar?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
Ralph Cook wrote:From eclipse, this runs fine and returns the icon. I don't reach "past new icon" when I am executing the jar file, and the imageURL is null.


How, exactly, did you run the program outside of the IDE? Command line? what command? or did you just double-click an executable jar?


I put it in c:\local, started a dos prompt window, changed my default directory to c:\local, and entered "java -jar durz.jar". The program ran ok, but blew up when I hit this code.

rc
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SSCE helps again; I'm on Windows, and in eclipse, case is not significant on the resource file. It is significant, however, in the jar. So the case of the resource filename must be the same as stored in the jar.

thanks!
rc
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow really? That's an eye-opener for me as well.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you put "Expanded.GIF" in a sub-directory named "images", it works from a jar unless/until you change the capitalization on the filename.

It makes sense; the zip file format has to be usable across OSs, so it has to handle (and distinguish among) different cases of filename.

rc
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic