Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm still experimenting with some OpenGL in LWJGL, and as I get to know more and more about OpenGL, I start to do more complicated things like multi texturing, shadowmapping and more. Now, right now I'm using the src folder (src/res) for my resources, and use src/resourcename in my code. When I export it, this won't work on another location as the relative path is ofcourse incorrect. What would be the best way of deploying your game with all the resources in one file? Maybe put the files in the jar?

I would like to hear from a few people how they store and deploy their project with resources, thanks!

share|improve this question
    
This isn't such a great fit for Q&A; we try to avoid listing resources and the like that are too, too bias. –  Vaughan Hilts Mar 13 '13 at 13:51
add comment

1 Answer 1

up vote 4 down vote accepted

Don't put the resources in your source folder. Instead do something like this:

  • Project root
    • src
    • res
      • images
      • shaders
      • sounds

There are two common ways to load resources in Java applications.

1. File system

In the code you can load the resources from file system with relative path "res/images/filename.png". While developing, use Project root as the working directory. When deploying the project, just copy the res folder to the same folder where the executables are located. You can also omit the res folder if you want to or call it something else.

2. JAR resources

Add the res folder to your classpath. You can then load the resources using ClassLoader.getResourceAsStream("images/filename.png"). Note the missing res folder from the path. When deploying, add the content of res folder to your .jar file.

It's also possible to put local resources next to the source files even deep in the package hierarchy. These resources can be loaded with Class.getResourceAsStream("relativepath"), where path to the resource is relative to the package of the class calling this method. I would not recommend this approach for game assets.


If the resources are considered as read-only after deployment, I would recommend the second approach. If on the other hand the player is allowed to modify or add resources to the game, the first approach works better.

share|improve this answer
    
Thank you for your clear answer! –  Basaa Mar 13 '13 at 16:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.