Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Game works in eclipse, but...  (Read 286 times)
0 Members and 1 Guest are viewing this topic.
Offline TFDizzy
« Posted 2014-05-09 19:23:16 »

Hey guys, I just made my first basic java game, which is just a 2D, pong type shooter. It works if I run it in Eclipse, but when I export it too a .Jar it won't load any of my graphics.

Is it maybe my graphics aren't being exported? I selected export and compress files into jar at the option screen, but no luck.

If anyone can help me that'd be great!
Offline Mr.CodeIt

Junior Devvie





« Reply #1 - Posted 2014-05-09 19:25:54 »

Hey guys, I just made my first basic java game, which is just a 2D, pong type shooter. It works if I run it in Eclipse, but when I export it too a .Jar it won't load any of my graphics.

Is it maybe my graphics aren't being exported? I selected export and compress files into jar at the option screen, but no luck.

If anyone can help me that'd be great!

I have the same problem except in LWJGL. are you using Java2D for your game?

I'm not drunk, I've just been up late coding.
Offline TFDizzy
« Reply #2 - Posted 2014-05-09 19:29:22 »

Nope, just using JFrame!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Drenius
« Reply #3 - Posted 2014-05-09 19:29:39 »

Are you loading your images from files or ressources?
Offline pjt33
« Reply #4 - Posted 2014-05-09 19:31:01 »

Is it maybe my graphics aren't being exported? I selected export and compress files into jar at the option screen, but no luck.
If you want to check whether the graphics are in the jar or not, either use jar tf at the command line or rename it to .zip and open it with your favourite unzipper.

But the typical problem here is getting the structure for the resource path wrong. If you want help debugging, it would be useful if you post the relevant snippets of code, the relevant snippets of the jar structure, and the exception message.
Offline Cero
« Reply #5 - Posted 2014-05-09 19:31:05 »

show as A) your folder structure and B) how you load it

Offline TFDizzy
« Reply #6 - Posted 2014-05-09 19:34:55 »

Ah yes, the pictures aren't being added. I'm calling them in via locally using a folder in eclipse. Anyway to solve this?
Offline Drenius
« Reply #7 - Posted 2014-05-09 19:45:59 »

Place them in a package (or the default one) and load them via
1  
ClassLoader.getSystemResourceAsStream("path/to/file/inside/jar")


Or create a folder with the images next to the jar, named as the original folder.
Offline Mr.CodeIt

Junior Devvie





« Reply #8 - Posted 2014-05-09 19:47:44 »

Ah yes, the pictures aren't being added. I'm calling them in via locally using a folder in eclipse. Anyway to solve this?

Do you know the exact location of that folder? It would be something like C:/Users/OwnerName/eclipse/workspace/folderName /TheImage.png

I'm not drunk, I've just been up late coding.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 273
Exp: 5 years



« Reply #9 - Posted 2014-05-09 19:48:23 »

Someone posts this same problem about every other day.

In short: use <yourClassName>.getResourceAsStream(...), don't use new File(...), it won't work when your project is a jar.

Google getResourceAsStream() for usage, special cases, etc.


Do you know the exact location of that folder? It would be something like C:/Users/OwnerName/eclipse/workspace/folderName /TheImage.png

Don't ever use absolute paths in an application.
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.

toopeicgaming1999 (57 views)
2014-11-26 15:22:04

toopeicgaming1999 (51 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (27 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!