• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Loading resources - Jar files

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem has probably been posted before but I couldn't find it in the beginner forums..sorry if it has already been answered.

My file structure is simple, I have all of my resource files (images, sounds and configuration files) inside my working directory. To load these files, I use their relative path using URL, for example, to load the images:
URL url = this.getClass().getClassLoader().getResource(fileName);

When I jar all of these files, I end up with something like this (inside the jar):
Model // java package
GUI // java package, where my main class is located
META-INF
a.jpg
b.jpg
...
...

and my manifest file looks like:
Manifest-Version: 1.0
Main-Class: GUI.Game

The main class gets executed fine, but the images don't show up, so I guess they are not located by my code. Any ideas how the jar file should be so as to fix this problem?

Thanks.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't need to change the JAR file at all, but when you execute the file, you need to make sure the JAR file is in the CLASSPATH. ie:

java -classpath ".;myimages.jar" Program

That should fix your problems, so long as all your relative paths in your program are set correctly.
 
Henrique Boreg
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it using the command line as you said and was able to see the runtime error it was throwing...turned out to be that some of my configuration files looked for *.png to load while some of the actual files were *.PNG...renaming them all to lowercase solved the problem. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic