Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
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  
  Help the Noob, Jar Files  (Read 1568 times)
0 Members and 1 Guest are viewing this topic.
Offline DarkMortar

Junior Member




Java Padawan


« Posted 2007-01-30 06:50:05 »

Ok, first of all, YES I know how to make jar files in eclipse. I have made sucessful jar files with several programs, like kev glass' tutorials into jar form.

BUT, I am having issue with packing my program. My Hex Map program, is somewhat based  off of the kev glass tut, but when I pack mine, and i excecute it through the command promt, so i can see what it prints, it prints some of my debug variables, then it says it cant find the graphic references, as i stated it should do in the program if it doesnt find the .pngs. YES, i thought that i included all of my graphics and resources in the program, but when i click my jar NOTHING happens, just those few prints in the command promt.

Heres how i handel images:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
public Graphic getGraphic(String ref, String type) {
     
      // if we've already got the sprite in the cache
     // then just return the existing version
     if (graphics.get(ref) != null) {
         return (Graphic) graphics.get(ref);
      }
     
      // otherwise, go away and grab the sprite from the resource
     // loader
     BufferedImage sourceImage = null;
     
      try {
         // The ClassLoader.getResource() ensures we get the sprite
        // from the appropriate place, this helps with deploying the game
        // with things like webstart. You could equally do a file look
        // up here.
        URL url = this.getClass().getClassLoader().getResource(ref);
         
         if (url == null) {
            fail("Can't find ref: "+ref);
         }
         
         // use ImageIO to read the image in
        sourceImage = ImageIO.read(url);
      } catch (IOException e) {
         fail("Failed to load: "+ref);
      }
     
      // create an accelerated image of the right size to store our sprite in
     GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
     
      /** Keenan's Renderer Mod */
      if (type=="oGRAPHIC") {
         image = gc.createCompatibleImage(sourceImage.getWidth(),
                                        sourceImage.getHeight(),Transparency.OPAQUE);
      }
      else if (type=="tGRAPHIC") {
         image = gc.createCompatibleImage(sourceImage.getWidth(),
                                        sourceImage.getHeight(),Transparency.TRANSLUCENT);
      }
     
      // draw our source image into the accelerated image
     image.getGraphics().drawImage(sourceImage,0,0,null);
     
      // create a sprite, add it the cache then return it
     Graphic graphic = new Graphic(image);
      graphics.put(ref,graphic);
     
      return graphic;
   }



I have loaded my images like this:
1  
2  
3  
4  
if      (TEXTURE == GRASSLAND) { 
         return GraphicStore.get().getGraphic(
               "\\ART\\TERRAIN\\GRASSLAND\\hex_green.png","tGRAPHIC");
      }

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2007-01-30 07:03:07 »

"\\ART\\TERRAIN\\GRASSLAND\\hex_green.png"

Well, those are backslashes. Roll Eyes

弾幕 ☆ @mahonnaiseblog
Offline DarkMortar

Junior Member




Java Padawan


« Reply #2 - Posted 2007-01-30 07:08:12 »

so? it excecutes perfectly in the ide, with pictures, its supposed to be backslash?

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

JGO Coder


Medals: 1


pixels! :x


« Reply #3 - Posted 2007-01-30 07:32:33 »

\  = backslash (a windows thing)
/ = slash (works everywhere)
URL = something with slashes
broken URL = something with backslashes

弾幕 ☆ @mahonnaiseblog
Offline DarkMortar

Junior Member




Java Padawan


« Reply #4 - Posted 2007-01-30 07:54:15 »

sp, i replaced it with:

"/ART/TERRAIN/OCEAN/hex_blue.png","tGRAPHIC");

and it cant find ref in ide so it doesnt work!

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #5 - Posted 2007-01-30 09:34:11 »

>and it cant find ref in ide so it doesnt work!

Then there is no "/ART/TERRAIN/OCEAN/hex_blue.png" in any jar/dir in the classpath.

---

http://kaioa.com/k/jarimage.jar

Source included.

弾幕 ☆ @mahonnaiseblog
Offline DarkMortar

Junior Member




Java Padawan


« Reply #6 - Posted 2007-01-31 01:30:38 »

there is no source with that file.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #7 - Posted 2007-01-31 23:56:57 »

There is.

弾幕 ☆ @mahonnaiseblog
Offline DarkMortar

Junior Member




Java Padawan


« Reply #8 - Posted 2007-02-01 02:28:08 »

well i aint know how to get it, all i get is a jar

Offline woogley
« Reply #9 - Posted 2007-02-01 03:47:05 »

this will blow your mind:




ready?




jars are zip files.

boom! now have at it Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DarkMortar

Junior Member




Java Padawan


« Reply #10 - Posted 2007-02-01 04:14:52 »

man, im an idiot i got it now.

Offline DarkMortar

Junior Member




Java Padawan


« Reply #11 - Posted 2007-02-01 04:27:35 »

Problem is i have loaded my images just like you with the imageIO reader thingy, but i use a class.

Yet when i switch the "//" to "/" it cant fine the ref, but heres a pick of my directory with my profram, and i use a package, and ART folder is where my images are.

http://img390.imageshack.us/img390/1412/help1ua9.png

I use this in quote to load for my class with the IO reader:
"/ART/TERRAIN/GRASSLAND/hex_green.png"

and it doesnt work when its not "//"

Offline Kova

Senior Member





« Reply #12 - Posted 2007-02-01 14:15:49 »

...
...

again I don't know what is the problem, here's how I do it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
...
BufferedImage game_paused_bfimg = loadAndCreateCompatibleImage("images/game_paused.png", BufferedImage.TRANSLUCENT);
...

    /** load image from PATH and make it compatible so it can be accelerated
     * @author Kova (kova1337@gmail.com)
     * @param path - relative path to image, ex.: "images/some_image.png"
     * @param image_type - type of BufferedImage
     * @return compatible loaded BufferedImage or null if reading fails
     * @see Transparency.OPAQUE, .BITMASK, .TRANSLUCENT
     */

   public BufferedImage loadAndCreateCompatibleImage(String path, int image_type) {
            URL url = null;
       try {
          url = this.getClass().getClassLoader().getResource(path);
                GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
                BufferedImage temp1_bfimg = ImageIO.read(url);
                BufferedImage temp2_bfimg = gc.createCompatibleImage(temp1_bfimg.getWidth(), temp1_bfimg.getHeight(), image_type);
                temp2_bfimg.getGraphics().drawImage(temp1_bfimg, 0, 0, null);
           return temp2_bfimg;
       } catch (Exception e) {
          System.out.println("Error loading image: " + path + " " + url);
          System.exit(0);
          return null;
       }
   }
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #13 - Posted 2007-02-01 20:00:14 »

If I understand correctly, you have packaged your ART folder in a jar, right?
1) Is the jar in your classpath when you start your program?
2) Did you check if the contents of your jar indeed includes that paths you expect?
3) Did you check the capitalization of the paths?

You definitely need forward slashes and no backslashes. Back slashes might work on the windows filesystem, but it won't anywhere else.
You could also try to skip the first (forward!) slash.

Offline DarkMortar

Junior Member




Java Padawan


« Reply #14 - Posted 2007-02-02 00:58:33 »

[size=10pt][size=10pt]WOW[/size][/size]

IT WORKED!!!

ALL  I had to do was this instead:
"ART/TERRAIN/GRASSLAND/hex_green.png"

NO SLASH in BEGINNING! Before, I tried it, I had a "/" at the beginning and it failed. Now my jar WORKS!!

Thank you guys!!

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.

CogWheelz (18 views)
2014-07-30 21:08:39

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

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

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

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

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

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!