Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
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  
  Exporting a Final Project  (Read 832 times)
0 Members and 1 Guest are viewing this topic.
Offline bstrauch24

Junior Newbie

Exp: 2 years

« Posted 2014-07-08 20:58:27 »

I just recently finished a game using pure Java (no libraries like libgdx or lwjgl). When I exported it from Eclipse (Right-Click Project > Export... > Java > Runnable JAR File > Extract / Package Required Libraries Into Generated JAR > Finish) when opened, the JAR file showed a blank (grey) JFrame without any graphics drawn onto it. Could this be a problem with my code, (even though it runs fine in Eclipse)? Or possibly the way that I am exporting it? I am also using a sprite sheet for a pixel font in the game, but the background and characters are created in the game, so that most likely isn't the problem.
Offline death_angel
« Reply #1 - Posted 2014-07-08 21:01:20 »

your images folder need to be next to the jar file.

I am just a guy
Offline bstrauch24

Junior Newbie

Exp: 2 years

« Reply #2 - Posted 2014-07-08 21:04:45 »

Thanks for the help! It worked, but how can I prevent players from modifying the sprite sheets?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline death_angel
« Reply #3 - Posted 2014-07-08 21:06:49 »

Sorry i dont know any method to do that :/

I am just a guy
Offline danieldean

Senior Devvie

Medals: 5
Projects: 1

« Reply #4 - Posted 2014-07-08 21:17:02 »

If the images don't need to be edited then you can put them in your JAR instead.

I usually use NetBeans but I have Eclipse as well so I'll try to guide you through doing this. First make a folder in the root of your project where you want to store your images, if you don't already have one, and put the images in it. I'd use 'res' or 'img' as the name to make your intent clear.

Next open Eclipse and right click on the project, go to 'Java Build Path' and click on 'Add Folder', find and select the folder you used in the previous step. You should now see this next to 'src' in Eclipse. Anything in here will now be put in your JAR.

You will probably need to change the code to load these images. Something like:


Should do this for you, this gets you an InputStream. Note the slash, you will need it. Or maybe:


Which gets a URL.

Hope this helps!
Offline bstrauch24

Junior Newbie

Exp: 2 years

« Reply #5 - Posted 2014-07-08 21:32:49 »

Thanks for your help! I have the build path set up, but I still don't understand the way that you suggested loading the images. Currently, I am using Buffered Images and storing the data in an array of pixels:

private BufferedImage image;
image = File("res/spritesheets/font.png"));

private int[] pixels;
pixels = image.getRGB(0, 0, width, height, pixels, 0, width);
Offline danieldean

Senior Devvie

Medals: 5
Projects: 1

« Reply #6 - Posted 2014-07-08 21:35:50 »

Simple, replace:

1 File("res/spritesheets/font.png"));



 Putting "/font.png" in there as the name should work. Wink
Offline Riven
« League of Dukes »

« JGO Overlord »

Medals: 1018
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #7 - Posted 2014-07-08 21:43:54 »

Please allow my pre-emptive strike Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline danieldean

Senior Devvie

Medals: 5
Projects: 1

« Reply #8 - Posted 2014-07-08 22:08:35 »

Fair point. Last time I did this I just used the default package. In this case assuming 'res' is the package folder and spritesheets the package "/spritesheets/font.png" would appear to be what is actually needed. Or at least it was in my dummy. Nice utility by the way. I'm sure that'll come in handy...  Cheesy
Offline bstrauch24

Junior Newbie

Exp: 2 years

« Reply #9 - Posted 2014-07-08 22:27:20 »

Thank you everyone for the help. After this addition, there is a slight 2 second lag during startup, but the game seems to be running fine.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Riven (24 views)
2015-07-27 16:38:00

Riven (14 views)
2015-07-27 15:35:20

Riven (19 views)
2015-07-27 12:26:13

Riven (9 views)
2015-07-27 12:23:39

BurntPizza (24 views)
2015-07-25 00:14:37

BurntPizza (36 views)
2015-07-24 22:06:39

BurntPizza (20 views)
2015-07-24 06:06:53

NoxInc (23 views)
2015-07-22 22:16:53

NoxInc (15 views)
2015-07-22 22:13:39

Jesse (36 views)
2015-07-22 03:10:36
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!