Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 1364 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: 75
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  

EgonOlsen (77 views)
2018-06-10 19:43:48

EgonOlsen (57 views)
2018-06-10 19:43:44

EgonOlsen (77 views)
2018-06-10 19:43:20

DesertCoockie (259 views)
2018-05-13 18:23:11

nelsongames (157 views)
2018-04-24 18:15:36

nelsongames (156 views)
2018-04-24 18:14:32

ivj94 (897 views)
2018-03-24 14:47:39

ivj94 (161 views)
2018-03-24 14:46:31

ivj94 (810 views)
2018-03-24 14:43:53

Solater (174 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!