Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Loading resourcen in WebStart  (Read 1627 times)
0 Members and 1 Guest are viewing this topic.
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Posted 2006-11-30 16:14:36 »

Hi,
  I've posted a game that I'm working here. I did the JNLP file for it but when I run it with webstart causes an exception. If I download the jar file it runs ok. (Also is running OK in eclipse)
I'm using the Kev's tip to load resources with
1  
Thread.currentThread().getContextClassLoader().getResourceAsStream(file)


I don't know if it is a problem with the data or the method used to access the images.

Here are the links:
Executable Jar
WebStart

   Rafael.-
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #1 - Posted 2006-11-30 16:22:18 »

The method is right, but the string that you should be supplying is from the root directory. So say you have this:

1  
2  
3  
4  
5  
com
    res
        image.png
    stuff
        myClass


You would access image.png from myClass by using "com/res/image.png". Is that what you are doing?

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #2 - Posted 2006-11-30 16:36:06 »

"/com/res/image.png"

The leading slash is important.

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #3 - Posted 2006-11-30 16:46:19 »

My directories are
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
App.class
object
  Ball.class
  Board.class
  *
sound
  SoundFXController.class
  *
res
  balls.png
  stars.png
  fx
    plick.wav
    *


And my code is the next
1  
image = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("res/combo.png"));


Before I was using
1  
image = ImageIO.read(getClass().getClassLoader().getResourceAsStream("/res/combo.png"));


When I changed the method the leading slash didn't work, so I removed it.

I think the access is working because the sound fx are loaded first. The problem is that the images don't work.

This happens only in the webstart, but not if executing the jar. (The webstar uses the same jar).

   Rafael.-
Offline noblemaster

JGO Ninja


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #4 - Posted 2006-11-30 20:05:12 »

I don't think the leading slash is a good idea. On Linux/UNIX, the leading slash indicates the very top of your directory structure ... You want to access your files using a relative path, so DO NOT use a leading slash.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #5 - Posted 2006-11-30 21:13:51 »

I don't think the leading slash is a good idea. On Linux/UNIX, the leading slash indicates the very top of your directory structure ... You want to access your files using a relative path, so DO NOT use a leading slash.

This is a java thing. NOT a os thing.

The leading slash makes its pseudo absolute (relative to the roots of the classpath).

See this example:
http://kaioa.com/k/jarimage.jar (doubleclickable/src included)

See javadoc:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

弾幕 ☆ @mahonnaiseblog
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2006-11-30 21:58:41 »

The leading slash thing is only true if you're using

1  
Class.getResourceAsStream()


because in that case the path specified has the context of the class. You need the leading slash to get out of the Class's package context. If you're using

1  
ClassLoader.getResourceAsStream() 


as with getContextClassLoader() then the leading "/" is redundant because there is not a package context from a class. Unfortunately using the leading slash in this method fails on some systems.

Kev

Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #7 - Posted 2006-12-01 14:06:59 »

Well,
   Then the access is OK, but the image loading fails.

   The jar executed directly works. But webstart gives me an error trying
to load the image.

   Has webstart some kind of restriction in the resources loaded inside a jar???

    Could you try the links to see if it works??
   WebStart
   Executable Jar

      Rafael.-
Offline kevglass

JGO Kernel


Medals: 120
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #8 - Posted 2006-12-01 14:23:27 »

Webstart works fine here (Windows). What platform is it failing on? Are you wrapping the input streams from the class loader in a BufferedInputStreams - that needed to be done at one point - not sure if it's still true.

Kev

Offline rdcarvallo

Senior Member


Projects: 5
Exp: 15 years


2D Java games forever!


« Reply #9 - Posted 2006-12-01 18:12:22 »

Compiled in jdk1.4.2_03  in Win2000
Tested in the same PC.

I didn't try it in my home... (jdk1.5.0 in WinXP)

Wrapping in  a BufferedInputStream.. I'll try that also.

Rafael.-

EDIT: The BufferedInputStream workaround fixed it.
 
   Thanks.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (13 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!