Can find file on netbeans, cant find file in jar?

The exact same code, while run in netbeans, works 100% but when I run it in a JAR file, it can’t find the file. I use this code to locate it:

    LifeFactory.initFactory(getClass().getResource("/renoria/resources/data/Mob").getFile());
    MapFactory.initFactory(getClass().getResource("/renoria/resources/data/Map").getFile());

Both of those work when I’m in NetBeans, but they fail when I run it in CMD java -jar “…”

Help me please.

I’ve had a lot of trouble with the Java resource loader recently, and I don’t know why either. Maybe aliens invaded my Java VM. :slight_smile:

Basically what I did in the end for my recent game (for LD13) was I hosted the resources on my website, then when the thing was first started I downloaded them all to a local folder for future access. This can be done pretty easily with URL’s, and if you’re resources are zipped you can actually make it faster for user, not to mention give them a pretty splash screen or better looking loading bar (rather than the built in applet or JWS ones).

The problem? It’s a pain in the butt, and means more programming on your end. Plus, you need either a signed applet or JWS, and you also need to be on a system where the user had correct admin-y type access to the local resources.

But it’s a workaround. :-\

Umm, Id rather not download them from my site, it is easier putting them in the Jar file.

In netbeans the resources reside in the build directory. If you packaage them as jar you can’t use .getFile() on your resource anymore because now they are a jar entry and not a file on the disk anymore. Let your LiveFactory and MapFactory handle URLs or InputStreams instead.

Fixed it, I used getResourceAsStream instead.