I prefer to not create a txt with an image index. This does not seem to be very productive and slows down the developement. I finally created a data initialization that automatically checks if it is a jar or not during the runtime and chooses the correct way to load files, works perfect for me:
try {
if (Game.class.getResource("/" + Game.class.getName().replace('.', '/') + ".class").toString().startsWith("file"))
loadFiles();
else
loadResources();
} catch (Exception e) {
e.printStackTrace();
}
static void loadFiles() {
try {
for (String n : new File(ClassLoader.getSystemResource("i").toURI()).list())
i.put(n.substring(0, n.indexOf('.')), new Image("i/" + n));
} catch (URISyntaxException | SlickException e) {
e.printStackTrace();
}
try {
for (String n : new File(ClassLoader.getSystemResource("f").toURI()).list()) {
if (n.endsWith("t")) {
n = n.substring(0, n.indexOf('.'));
f.put(n, new AngelCodeFont("f/" + n + ".fnt", "f/" + n + ".png"));
}
}
} catch (URISyntaxException | SlickException e) {
e.printStackTrace();
}
}
static void loadResources() {
try {
Enumeration<JarEntry> en = new JarFile("gametest.jar").entries();
while (en.hasMoreElements()) {
JarEntry n = (JarEntry) en.nextElement();
String name = n.getName();
if (name.startsWith("i") && name.indexOf('.') > -1)
i.put(name.substring(2, name.indexOf('.')), new Image(name));
if (name.endsWith("fnt"))
f.put(name.substring(2, name.indexOf('.')), new AngelCodeFont(name, name.substring(0, name.indexOf('.')) + ".png"));
}
} catch (IOException | SlickException e) {
e.printStackTrace();
}
}