In Java, where should the resources / resources be located in the package / source hierarchy?

Let's say I developed a game and put it in the package structure:

com.dxmio.games.breakout 

Where is the place of "best practice" for placing resources such as sound and images that the game uses?

+6
java resources packages
source share
2 answers

I saw how this was handled in several ways:

  • Put the resources directly in the com / dmxio / games / breakout subdirectory (e.g. /com/dmxio/games/breakout/images/foo.gif and /com/dmxio/games/breakout/images/bar.gif)
  • Put your resources in the jar with your class files (for example, foo.gif and bar.gif included in breakout.jar)
  • Put your resources in a separate "Resource jar" in a subdirectory in com / dmxio / games / breakout (for example, foo.gif and bar.gif in the set /com/dmxio/games/breakout/images/images.jar)

I prefer the last option.

Then you can use the java.lang.Class.getResource () method to extract your resources.

+9
source share

You can always take Maven's standard approach to your project and put all the application source files in

{home} / src / home / java / com / dmxio / games / breakthrough

and then your resources live in

{home} / src / core / resources / com / dmxio / games / breakthrough

Then your tests live in:

{home} / src / test / java / com / dmxio / games / breakthrough

This structure is the standard convention for structuring projects in the Maven world. This brings with it many benefits that you can look at. You can check the resource section here:

http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR

Alternatively :) another approach here is just good ...

+15
source share

All Articles