lwjgl, jarsplice, distributing problem

Im sure this has been answered before, but I will ask it anyway. I exported my lwjgl game and used jarsplice to create fat jar, simple.
But when runnng my game I get image not loaded exception. Basically textures failed to load. Do I have to make some sort of workaround for this to work? I use slick Textureloader and imageIO for a couple of images which works perfectly when debugging from eclipse. It seems I get exception under imageIO.

How can I get it to work?

can you paste the full exception?

If I was to guess, I’d say you are using File to load the image when you should be using an InputStream for images that are in a jar, but will need to see exception to confirm.

Well I load this single image as bufferedImage, and catch exception which i can see later when running:


public static void load(){
		imageMain = null;
		try {
			imageMain = ImageIO.read(new File("res/fonts/font.png"));	//loads main fonts image
		} catch (IOException e) {
			System.out.println("cant load fonts Image!");
			System.exit(0);
		}
	}

I use this one later to get subimages…

And then I load a bunch more textures using InputStream for “regular use”:


public static Texture basic;
	public static Texture orange;
	public static Texture blue;
	//public static Texture text;
	public static Texture menuBG;
	public static Texture stars;
	public static Texture moon;
	public static Texture redPlanet;
	public static void initTexs(){
		try {
			basic = TextureLoader.getTexture("PNG",new FileInputStream(new File("res/tex/basic.png")));
			orange = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/orange.png")));
			blue = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/blue.png")));
			stars = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/stars.png")));
			menuBG = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/menu/background.png")));
			moon = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/moon.png")));
			redPlanet = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/tex/redplanet.png")));
			System.out.println("Textures are loaded!");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Error while loading textures!");
			Display.destroy();
			System.exit(0);
		}
	}

Well there is your problem :), you can’t use File when reading images from a jar file, you need to use an InputStream. File only works when reading files from a file system (as you are when running from eclipse).

Since you are using Slick you should use its useful ResourceLoader class to do this automatically for you (so doesn’t matter if you are loading a file from a filesystem or a jar).

See the slick image loading tutorial here.

So with your code you wouldn’t use :

basic = TextureLoader.getTexture("PNG",new FileInputStream(new File("res/tex/basic.png")));

but instead use

basic = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/tex/basic.png"));

As for your ImageIO.read line you can still use ResourceLoader as follows:

imageMain = ImageIO.read(ResourceLoader.getResourceAsStream("res/fonts/font.png"));   //loads main fonts image

hope that helps.

Yep! It works now! Thank you for your help :slight_smile: