Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading from a JAR file

 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to load data from a file held in one of the jar files in the ARCHIVE parameter?
Basically, I've got a couple of property files that I'd love the applet to read when it gets initialised.
Can anyone help?
 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh I forgot, the applet must be able to run offline too.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee,
Here is how you would do it :

Where you would replace ClassName with the real name of your class, and image.gif with the real name of the image you are loading ( along with it's path in the JAR file if applicable ). This will work both on and offline.
HTH,
-Nate
 
Lee Feder
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nate, it works a treat.
 
Khurram Fakhar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , ppl
It is working fine in IE but it is giving error with NS..
Kindly help me out
Regards
Khurram Fakhar
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... Ummm... could you say what error it is giving in Netscape...
 
Khurram Fakhar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works fine with
URL url1 = ClassName.class.getResource("loginpage_image.jpg");
but on the second line it gives the following error:
line :
panelImage=Toolkit.getDefaultToolkit().getImage(url1);
error :
java.lang.NullPointerException
at sun.awt.SunToolkit.getImageFromHash(Compiled Code)
at sun.awt.SunToolkit.getImage(Compiled Code)
at ClientMain.images(Compiled Code)
at ClientMain.init(Compiled Code)
* at netscape.applet.DerivedAppletFrame$InitAppletEvent.dispatch(Compiled Code)
at java.awt.EventDispatchThread$EventPump.dispatchEvents(Compiled Code)
at java.awt.EventDispatchThread.run(Compiled Code)
at netscape.applet.DerivedAppletFrame$AppletEventDispatchThread.run(Compiled Code)

but working fine with IE .. ..
isn't it strange ?

regards
Khurram Fakhar
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... I don't have Netscape here at work to test it out on, but have you tried to replace :


with :


( I assume you are doing this in an Applet... )

Hopefully this works... if not please post again...


-Nate
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, ignore the previous post... I did a search on this and found that Netscape's getResource() method is broken...

Here's some code I found in a JavaWorld article ( http://www.javaworld.com/javaworld/jw-07-1998/jw-07-jar_p.html ) that should help you out...



You should call it in your code like this:


HTH,
-Nate
 
Khurram Fakhar
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hay Thanx a million Man
It worked. I studied the whole article .. very well written article .
Thanx once again ..
Regards
Khurram Fakhar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic