Loading textures from jar file

This is only somewhat related to jME, but I figured I would go ahead and ask to see if anyone else has ran into this problem.  In my RPG Toolset I want to pack a group of resource files into a jar file for game distribution, but I am running into a problem with texture loading.  I am using the java.util.jar package (JarOutputStream, etc.) to create the jar file.  For some reason when I try to run the game, it gets a FileNotFoundException when it tries to load the textures for my ASE models, however it is able to read the model files themselves and everything else from the jar.  It also does this if I manually create the jar using IZArc.  If I create the jar using the "jar" tool from the command line everything works fine.  I've checked in the jar files and it looks like everything is there, including a correct manifest, but there is a few KB difference in the file sizes.  Has anyone ran into this or have any ideas what would cause this?  There's other routes I could take, but I'd prefer to figure this way out if I can… Thanks!

It does work with jar but not with IZArc? Use jar then :slight_smile:

If you have the problem with the jar tool, too: what did you specify as tex_url?

The jar tool works perfectly, but for my toolset I want to create the jar for the user from within the Java code without having to call an external system command…

Oh, ok, seems I read your first post a little too fast. Creating a jar with the jdk classes should be fine, too. Can you post a working and a not-working jar for us to compare?

Here are examples of a working and a not-working jar.  The one named “resources.jar” is the working one, and I named the not-working one “resources_bad.jar”.  I just noticed something in IZArc, if I go to file properties for the bad one, it says 9 files, but if I go to file properties for the good one, it says 17 files (there’s only 9 actual files, but 17 would be the total if you count directories also).  All the directories seem to be there in the bad one, though.  I also included some code below of how I load the resources.  As I mentioned before, this works fine as is if I use the jar tool the create the jar…



URL input = Utility.getURL(resourcePath + "/tilesets/" + tileset + "/" + type + "/" + type + ".ase");
URL textureDir = Utility.getURL(resourcePath + "/tilesets/" + tileset + "/" + type + "/");
AseToJme aToJ = new AseToJme();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
   aToJ.convert(new BufferedInputStream(input.openStream()), baos);
   tileNode = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(baos.toByteArray()));

Looks like I may have figured out my problem… After noticing the difference in file counts, I added some code to create separate jar entries for each directory as below, and it seems to be working now. :)  I'm guessing the textures were the only things not working because that was the only case where I would try to reference a directory in the jar as opposed to a file.

   JarOutputStream out = new JarOutputStream(stream, manifest);
   JarEntry entry = new JarEntry("resources/maps/");
   entry = new JarEntry("resources/tilesets/");

(The trailing slashes specify the entry as a directory)