Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  jaring freakin sucks  (Read 1446 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Posted 2004-02-06 13:00:13 »

Here's the deal.

Jaring works when all your content is in a class file.

Classes inside Jar files cannot read data that isn't from a Class file also inside the Jar. IE: pics, files.
I had to get my friend to download the external data files seperately. It worked then.

Why can't programs read image/data files while in the Jar?

I have done everything correctly.

http://members.optusnet.com.au/ksaho/Algorithm/JAVA/prototypes/neoRpg.jar

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #1 - Posted 2004-02-06 13:17:24 »

??

You CAN read everything from a jar. Just the correct URL is necessary. Which one do you use?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #2 - Posted 2004-02-06 13:19:16 »

Works fine for me, I do it all the time.  Usually using getResourceAsStream.

In fact my app has some graphics in a different jar, just so my app can be easily branded with different splash screens etc. by replacing that one jar file.  It all works without a hitch.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #3 - Posted 2004-02-06 13:31:10 »

I think that's why it never worked.

What would be the best way to do so?
Would it be better just for people to extract the data files to a specific path and run the Jar as is?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #4 - Posted 2004-02-06 13:33:50 »

Quote
I think that's why it never worked.

What would be the best way to do so?
Would it be better just for people to extract the data files to a specific path and run the Jar as is?


Huh? What are you talking about?  What are you referring to with "why it never worked"?
We are saying you don't need to extract the data files.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #5 - Posted 2004-02-06 13:37:57 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
import java.io.*;
import java.net.*;
import javax.imageio.*;
import java.awt.image.*;

public class ImageLoader
{
   public static BufferedImage load(String name)
   {
      BufferedImage image;
      try
      {
         URL imageUrl = ImageLoader.class.getResource(name);
         image = ImageIO.read(imageUrl);
      }
      catch(IOException ioe)
      {
         GUI.dm.printErr("couldn't load: "+name);
         image=null;
      }
     return image;
   }
}


BufferedImage img = ImageLoader.load("/gfx/shadow.png");

or

this.setIconImage(ImageLoader.load("icon.gif"));

etc

Pretty easy huh?

弾幕 ☆ @mahonnaiseblog
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #6 - Posted 2004-02-07 01:26:17 »

Quote


Huh? What are you talking about?  What are you referring to with "why it never worked"?
We are saying you don't need to extract the data files.


The data files need to be there because that's where all the content comes from.
Without it I have an empty program.

I'm a little dissapointed that I need to use "getResource" to get text files and pictures to be read from within the Jar file.

Thanks fellas.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #7 - Posted 2004-02-07 03:19:11 »

Ok smart guys, so how do you access a jar from an applet?
Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #8 - Posted 2004-02-07 08:00:49 »

?
You don't access the "jar", the VM just has a ClassLoader which has a Bunch of Stuff available to it, fed to it by various means like jars, either locally or remotely. The way you access resources on the classpath is the same no matter how the code is deployed, that is, you use
1  
someInstance.getClass().getResource("...");
or
1  
someInstance.getClass().getResourceAsStream("...");
to get it. If the classpath has your jar in it, it'll be able to find the resources in there. If you don't prepend a "/" to the path, then the path is assumed to be the "package path", eg. if the class is "com.foo.Blah" then no slash will look under "com/foo/" for resources. If you want to package stuff up at the root level, prepend the "/" to the path.

It's not rocket science!

Cas Smiley

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #9 - Posted 2004-02-08 23:03:53 »

Quote
I'm a little dissapointed that I need to use "getResource" to get text files and pictures to be read from within the Jar file.


Why disappointed?  That seems like a very odd thing to say.  Kind of like, "I'm disappointed that I have to name my main method 'main'."
er, yeah, that just sucks...Huh.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #10 - Posted 2004-02-15 20:41:43 »

I'm having all kinds of trouble with jars;

Edit: I fixed this... go ant....
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (82 views)
2013-05-17 21:29:12

alaslipknot (91 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.168 seconds with 21 queries.