Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 1728 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

JGO Kernel


Medals: 284
Projects: 3
Exp: 16 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (60 views)
2014-04-15 18:08:23

BurntPizza (58 views)
2014-04-15 03:46:01

UprightPath (71 views)
2014-04-14 17:39:50

UprightPath (54 views)
2014-04-14 17:35:47

Porlus (71 views)
2014-04-14 15:48:38

tom_mai78101 (97 views)
2014-04-10 04:04:31

BurntPizza (157 views)
2014-04-08 23:06:04

tom_mai78101 (252 views)
2014-04-05 13:34:39

trollwarrior1 (207 views)
2014-04-04 12:06:45

CJLetsGame (214 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!