packing resouces into JAR

Hello.
I’m having a stupid problem. I can’t properly pack a JAR :frowning:
I have manifest.mf file with: “Main-Class: viktorije.Viktorije”, directory (package) viktorije and Images directory (.png images). I use “jar -cfmv viktorije.jar manifest.mf viktorije Images” … classes are packet correctly but Images not. When I run it I get catched error it can’t load “Images\some_image.png”. How do I pack Images into jar? Thank you.

Edit:
I don’t know if it makes any difference, but here’s how I load images:


	public static BufferedImage loadImage(String path) {
		URL url = null;
	    try {
	    	url = Viktorije.class.getClassLoader().getResource(path);
	        return ImageIO.read(url);
	    } catch (Exception e) {
	    	System.out.println("Error loading image: " + path + " " + url);
	    	System.exit(0);
	    	return null;
	    }
	}

That backslash in your image path makes me very suspciious.

Are you sure its not that?

you can use jar -tf to see what is really in the jar.

Yeah, thanks Jeff.
It was backslash… when I put slashes instead it worked in JAR. So I guess using slashes for path is the right way… don’t know why backslashes work also then. :-[

Well apparently they dont since you tried it that way and it failed.

Having said that, the right way to put a backslash in a string is “\”. A single slash just is an escape on the following character.

Yeah, I used “\” … when I said it works I meant directly running from Eclipse. Guess it’s a windows thing. Of course from .jar it dosen’t work.

AUIU when you say “from swing” you really mean from a local file. Windows udnerstands \ as part of ist file paths.

The code that reads from the JARs however is totally different code and inst going through windows path parsing.