Deploying madness w/ applets

Hey guys!

I know this one has been up before, but since the search function is crap… The rest you know.

I want to deploy my application w/ slick2d as an applet. I followed the nice tutorial on NinjaCave and it all works fine. Except, my game is not signed, and it can therefore not reach my resources, which is in the same jar.
So, either I change the way resources are loaded:

tilesheet = new SpriteSheet("res/tileset.png", TILE_WIDTH, TILE_HEIGHT);
background = new Image("res/background.png");

or, I sign the thing. After tons of looking around, it seems that signing is not exctly the easest thing in the world. It also seams that I need to register, and all kinds of legal things to do this, and I just can’t believe that.

So, what would be the easiest? Is there an easy way to sign my game, to gain acces?
Is there an easy way to load resources, that I don’t know of?

I hope someone comes along and says that Signing a jar isn’t that hard and explains EXACTLY how to do it, 'cause yea, I don’t get it either.

Does this work?


URL inMyJar = getClass().getResource("res/");
Image background;
background = getImage(inMyJar, "background.png");

I don’t use Slick2d (I’m assuming that’s where the SpriteSheet() comes from) but perhaps there is a way to load an image and convert it to a SpriteSheet?

I can’t initialize an Image that way. It needs to have the string reference. http://slick.cokeandcode.com/javadoc/

I’ve tried to create a keystore, and signing and verifying my game.jar , but I still get the permission-error, even when clicking yes in the permissions box. Even though I typed in all my information when prompted during signing it appears as UNKNOWN, and none of it is showed.


keytool -genkey -alias madshorndrup -keystore madskeystore
jarsigner -keystore madskeystore skrollr.jar madshorndrup
jarsigner -verify skrollr.jar

The whole process runs smoothly, and I looked to check I was getting the signature in the jars.

EDIT: With signing, I still get this error:



java.security.AccessControlException: access denied (java.io.FilePermission .\res\actors\spritesheet.png read)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkRead(Unknown Source)
	at java.io.File.exists(Unknown Source)
	at org.newdawn.slick.util.FileSystemLocation.getResourceAsStream(FileSystemLocation.java:52)
	at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:61)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:169)8/
	at org.newdawn.slick.Image.<init>(Image.java:196)
	at org.newdawn.slick.SpriteSheet.<init>(SpriteSheet.java:129)
	at org.newdawn.slick.SpriteSheet.<init>(SpriteSheet.java:115)
	at org.newdawn.slick.SpriteSheet.<init>(SpriteSheet.java:102)
	at com.javadaemon.skrollr.util.ResourceManager.initGraphics(ResourceManager.java:135)
	at com.javadaemon.skrollr.util.ResourceManager.init(ResourceManager.java:41)
	at com.javadaemon.skrollr.util.ResourceManager.<init>(ResourceManager.java:37)
	at com.javadaemon.skrollr.util.ResourceManager.getRessourceManager(ResourceManager.java:30)
	at com.javadaemon.skrollr.GameMain.init(GameMain.java:45)
	at org.newdawn.slick.AppletGameContainer$Container.initApplet(AppletGameContainer.java:272)
	at org.newdawn.slick.AppletGameContainer$ContainerPanel.initGL(AppletGameContainer.java:229)
	at org.newdawn.slick.AppletGameContainer$ContainerPanel.start(AppletGameContainer.java:216)
	at org.newdawn.slick.AppletGameContainer$1.run(AppletGameContainer.java:92)

Maybe it’s not accessing the right file. Try using a forward slash (’/’) at the beginning of the path to signify the root of the jar.
Also you do not need to sign a jar to be able to access resources inside it. However you do need to sign the jar to access files on the client’s file system AND to be able to load native code (which you must do to use Slick2D/LWJGL).

But lwjgl applet jar is allready signed and do not need own signing if those all only native files needed.

I agree with pitbuller. Signing your own jars is not required. The LWJGL jars are signed and that’s sufficient.
It must be a different problem.
My “StarCleaner” game runs as an applet and I didn’t sign a single jar file. All resources (images, sheets, etc.) are inside my starcleaner.jar and it is a Slick game. And I also followed Kappa’s tutorial on ninjacave to create Slick2D applets.

How did you access the resources?

Thanks for the replies guys. I will try to use the forward slash, and we will see where that goes.

You are trying to load a resource as a file from the filesystem. Applets are not allowed to do this unless the entire codebase is signed with all permissions granted. You probably actually want to load your resource from one of the applet jars.

Cas :slight_smile:

StarCleaner relies on some ResourceManager we built as part of MarteEngine. But inside it uses the standard Slick constructors like new Image(“relativeResourcepath”).
No magic at all except what’s happening inside Slick.
All resources are part of the jar of course.

If that’s the case for you, something like this should work:


Image background = new Image("res/background.png");

Feel free to browse our MarteEngine source code, the StarCleaner source code is also part of Marte (test/it/marteEngine/game/StarCleaner).

Hope that helps a bit and cheers,
Tommy

It looks like you did it with a stream some places, and with a filesystem others. I can’t build your game though, so I can’t check the “file” instance you initialize Images with. :frowning:

How would this be done?
I only see Image can be initialized the following ways, in Slick:


Image() 
Image(Image other) 
Image(ImageData data) 
Image(ImageData data, int f) 
Image(java.io.InputStream in, java.lang.String ref, boolean flipped) 
Image(java.io.InputStream in, java.lang.String ref, boolean flipped, int filter) 
Image(int width, int height) 
Image(java.lang.String ref) 
Image(java.lang.String ref, boolean flipped) 
Image(java.lang.String ref, boolean flipped, int filter) 
Image(java.lang.String ref, boolean flipped, int f, Color transparent) 
Image(java.lang.String ref, Color trans) 
Image(Texture texture) 

I cant even seem to get away with the input stream from class.getResourceAsStream(), nor the URL class.getResource()

You need to use Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);

Cas :slight_smile:

That is still as a stream, and in Slick, I can’t create the image from that :clue:

Isn’t there a constructor that takes an InputStream? :wink:

I can’t even get that constructor to work, because it also takes a string and a bool. :emo:

new Image(myInputStream, “path/to/file”, false);

So you suggest a new InputStream()?

No I’m suggesting you give it the same path you gave getResourceAsStream(String):


String resource = "path/to/file";
new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream(resource),resource,false);

background = new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("/res/background.png"), "/res/background.png", false);

Like this?

It outputs these:



Mon Nov 21 20:11:04 CST 2011 ERROR:Stream closed
java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
	at java.io.BufferedInputStream.available(Unknown Source)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:53)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:277)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231)
	at org.newdawn.slick.Image.load(Image.java:422)
	at org.newdawn.slick.Image.<init>(Image.java:269)
	at org.newdawn.slick.Image.<init>(Image.java:256)
	at com.javadaemon.skrollr.util.ResourceManager.initGraphics(ResourceManager.java:135)
	at com.javadaemon.skrollr.util.ResourceManager.init(ResourceManager.java:42)
	at com.javadaemon.skrollr.util.ResourceManager.<init>(ResourceManager.java:38)
	at com.javadaemon.skrollr.util.ResourceManager.getRessourceManager(ResourceManager.java:31)
	at com.javadaemon.skrollr.GameMain.init(GameMain.java:45)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
	at com.javadaemon.skrollr.GameMain.main(GameMain.java:77)
Mon Nov 21 20:11:04 CST 2011 ERROR:Failed to load image from: /res/tileset.png
org.newdawn.slick.SlickException: Failed to load image from: /res/tileset.png
	at org.newdawn.slick.Image.load(Image.java:425)
	at org.newdawn.slick.Image.<init>(Image.java:269)
	at org.newdawn.slick.Image.<init>(Image.java:256)
	at com.javadaemon.skrollr.util.ResourceManager.initGraphics(ResourceManager.java:135)
	at com.javadaemon.skrollr.util.ResourceManager.init(ResourceManager.java:42)
	at com.javadaemon.skrollr.util.ResourceManager.<init>(ResourceManager.java:38)
	at com.javadaemon.skrollr.util.ResourceManager.getRessourceManager(ResourceManager.java:31)
	at com.javadaemon.skrollr.GameMain.init(GameMain.java:45)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
	at com.javadaemon.skrollr.GameMain.main(GameMain.java:77)
Caused by: java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
	at java.io.BufferedInputStream.available(Unknown Source)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:53)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:277)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231)
	at org.newdawn.slick.Image.load(Image.java:422)
	... 10 more
 

Hmmm why was the stream closed?

This is what I’m doing:


private void initGraphics() throws SlickException {
		// Prepare the sprite sheet for use
		Image tilesheet1 = new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("/res/tileset.png"), "/res/tileset.png", false);
		tilesheet = new SpriteSheet(tilesheet1, TILE_WIDTH, TILE_HEIGHT);
		
		Image charsheet1 = new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("/res/actors/spritesheet.png"), "/res/actors/spritesheet.png", false);
		charsheet = new SpriteSheet(tilesheet1, 16, 24);
		
		// Create animations
		charAnimations = new HashMap<CHARANIM, Animation>();
		for (CHARANIM animationEnum : CHARANIM.values()) {
			int numberOfFrames = animationEnum.frames.length;
			Image[] frames = new Image[numberOfFrames];
			for (int i = 0; i < numberOfFrames; i++) {
				CHAR_IMAGE frameReference = animationEnum.frames[i];
				frames[i] = charsheet.getSubImage(frameReference.getX(), frameReference.getY())
				.getFlippedCopy(animationEnum.flipHorizontal, false);
			}

			Animation animation = new Animation(frames, animationEnum.length);
			animation.setPingPong(animationEnum.pingpong);
			charAnimations.put(animationEnum, animation); 
		}
		
		// Set up animation sets
		animationSets = new HashMap<ANIMATION_SET, AnimationSet>();
		AnimationSet animSet = new AnimationSet();
		animSet.addAnimation(DIRECTION.RIGHT.getID() | ANIMATION_STATE.STAND.getID(),
				CHARANIM.CHAR_STAND_RIGHT);
		animSet.addAnimation(DIRECTION.LEFT.getID() | ANIMATION_STATE.STAND.getID(), 
				CHARANIM.CHAR_STAND_LEFT);
		animSet.addAnimation(DIRECTION.RIGHT.getID() | ANIMATION_STATE.WALK.getID(), 
				CHARANIM.CHAR_WALK_RIGHT);
		animSet.addAnimation(DIRECTION.LEFT.getID() | ANIMATION_STATE.WALK.getID(), 
				CHARANIM.CHAR_WALK_LEFT);
		animSet.addAnimation(DIRECTION.RIGHT.getID() | ANIMATION_STATE.JUMP.getID(), 
				CHARANIM.CHAR_JUMP_RIGHT);
		animSet.addAnimation(DIRECTION.LEFT.getID() | ANIMATION_STATE.JUMP.getID(), 
				CHARANIM.CHAR_JUMP_LEFT);
		
		animationSets.put(ANIMATION_SET.GRAY_GUY, animSet);
		
		background = new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("/res/background.png"), "/res/background.png", false);
		background.setFilter(Image.FILTER_NEAREST);
	}

.and this is what happening:



Mon Nov 21 20:35:52 CST 2011 INFO:Slick Build #274
Mon Nov 21 20:35:52 CST 2011 INFO:LWJGL Version: 2.7.1
Mon Nov 21 20:35:52 CST 2011 INFO:OriginalDisplayMode: 1366 x 768 x 32 @60Hz
Mon Nov 21 20:35:52 CST 2011 INFO:TargetDisplayMode: 600 x 400 x 0 @0Hz
Mon Nov 21 20:35:52 CST 2011 INFO:Starting display 600x400
Mon Nov 21 20:35:52 CST 2011 INFO:Use Java PNG Loader = true
WARNING: Found unknown Windows version: Windows 7
Attempting to use default windows plug-in.
Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
Mon Nov 21 20:35:52 CST 2011 INFO:Found 2 controllers
Mon Nov 21 20:35:52 CST 2011 INFO:0 : Razer Mamba
Mon Nov 21 20:35:52 CST 2011 INFO:1 : Razer Mamba
Mon Nov 21 20:35:52 CST 2011 ERROR:Stream closed
java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
	at java.io.BufferedInputStream.available(Unknown Source)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:53)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:277)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231)
	at org.newdawn.slick.Image.load(Image.java:422)
	at org.newdawn.slick.Image.<init>(Image.java:269)
	at org.newdawn.slick.Image.<init>(Image.java:256)
	at com.javadaemon.skrollr.util.ResourceManager.initGraphics(ResourceManager.java:135)
	at com.javadaemon.skrollr.util.ResourceManager.init(ResourceManager.java:42)
	at com.javadaemon.skrollr.util.ResourceManager.<init>(ResourceManager.java:38)
	at com.javadaemon.skrollr.util.ResourceManager.getRessourceManager(ResourceManager.java:31)
	at com.javadaemon.skrollr.GameMain.init(GameMain.java:45)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
	at com.javadaemon.skrollr.GameMain.main(GameMain.java:77)
Mon Nov 21 20:35:52 CST 2011 ERROR:Failed to load image from: /res/tileset.png
org.newdawn.slick.SlickException: Failed to load image from: /res/tileset.png
	at org.newdawn.slick.Image.load(Image.java:425)
	at org.newdawn.slick.Image.<init>(Image.java:269)
	at org.newdawn.slick.Image.<init>(Image.java:256)
	at com.javadaemon.skrollr.util.ResourceManager.initGraphics(ResourceManager.java:135)
	at com.javadaemon.skrollr.util.ResourceManager.init(ResourceManager.java:42)
	at com.javadaemon.skrollr.util.ResourceManager.<init>(ResourceManager.java:38)
	at com.javadaemon.skrollr.util.ResourceManager.getRessourceManager(ResourceManager.java:31)
	at com.javadaemon.skrollr.GameMain.init(GameMain.java:45)
	at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:390)
	at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:314)
	at com.javadaemon.skrollr.GameMain.main(GameMain.java:77)
Caused by: java.io.IOException: Stream closed
	at java.io.BufferedInputStream.getInIfOpen(Unknown Source)
	at java.io.BufferedInputStream.available(Unknown Source)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:53)
	at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:277)
	at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231)
	at org.newdawn.slick.Image.load(Image.java:422)
	... 10 more