Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading resources - Jar files  RSS feed

 
Henrique Boreg
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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.
 
Jeremy Tartaglia
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!