Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (623)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
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 as .jar in eclipse  (Read 889 times)
0 Members and 1 Guest are viewing this topic.
Offline numpad

Junior Newbie

« Posted 2012-10-03 19:40:50 »

I just finished the alpha of my project and wanted to export it as a runnable .jar file.
To do this, I click on File -> Export..., select "runnable .jar file"and click "next".
Now, I select the Launch configuration and select an export destination. I accept it and export the .jar file.
After this, I ran the .jar, and it worked a bit. Everything's alright but the images and sounds. I don't see any images and don't hear any sounds. Things(rectangles etc.) I drew using Graphics class are shown.
That's the way I load the Images:
try {
    skin = File("res/guys/" + skinname +".png"));
} catch (Exception e) {System.out.println("eror loading skin at");}

That's the java project.

The .jar looks like this:

     +---> eclipse --> jdt --> internal --> jarinjarloader --> some classes Wink
     +---> MAINFEST.MF
     +---> companyname --> projektname --> my classes
I don't know where to place the resources. How can I handle and solve this problem?
Offline teletubo
Global Moderator

JGO Wizard

Medals: 67
Projects: 4
Exp: 8 years

« Reply #1 - Posted 2012-10-03 20:15:23 »

You should not load your resources that way.

Check this article:

Skip to the part "Getting at your resources", you'll see how you should do it and why.

Offline Cero
« Reply #2 - Posted 2012-10-03 21:07:04 »

you can also place the resources outside the jar and it will work.
however it wont work with applets and webstarts because these want to have it all in one jar (many jars is possible maybe, but jars nonetheless)

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2012-10-04 20:26:46 »

I put my resources in a package in the src folder, usually a subfolder, but at least something I can get to via a "../" or two if needed.

For example in the SimplexTexture tutorial I am working on, I have a packages called:

com.adonax.tutorial (for the code)
com.adonax.tutorial.images (for the images)

Code in the tutorial area (TutorialFramework is a class in this source folder) that loads a resource image would form the URL form as in the following:

      URL introURL = TutorialFramework.class.getResource(

I think this method is consistent with what is presented in the Java Tutorials. There is a description of resource loading under the topic of icons (go figure) that wasn't easy for me to find but I now have bookmarked:
See the section titled "Loading Images using getResource" about 1/3rd of the way down.

I don't know that this is best, only that it works for me.

Second note: I've never had much success with selecting export to "Runnable JAR file", and always the first option "JAR file". I confess I haven't bothered to learn the significance of the distinction, since the "JAR file" option works fine.

In general, I've found URLs to be the most reliable way to identify various files and resources, especially since subfiles in a compressed jar are kind of a special case and the File command can't necessarily peek inside a compressed file.

P.S., the author of "cokeandcode" is pretty reliable. I didn't look at his suggestions in this instance, but I'm betting there are good suggestions there.

music and music apps:
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

BurntPizza (28 views)
2015-10-08 03:11:46

BurntPizza (16 views)
2015-10-08 00:30:40

BurntPizza (19 views)
2015-10-07 17:15:53

BurntPizza (32 views)
2015-10-07 02:11:23

KaiHH (38 views)
2015-10-06 20:22:20

KaiHH (16 views)
2015-10-06 19:41:59

BurntPizza (32 views)
2015-10-06 19:04:48

basil_ (46 views)
2015-09-30 17:04:40

shadowstryker (25 views)
2015-09-29 15:55:06

TheSpaceHedgehog (31 views)
2015-09-29 01:58:48
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 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!