Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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 731 times)
0 Members and 1 Guest are viewing this topic.
Offline numpad

Junior Newbie





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

Hey,
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:
1  
2  
3  
try {
    skin = ImageIO.read(new File("res/guys/" + skinname +".png"));
} catch (Exception e) {System.out.println("eror loading skin at guy.java");}


That's the java project.


The .jar looks like this:

   org
     |
     +---> eclipse --> jdt --> internal --> jarinjarloader --> some classes Wink
   META-INF
     |
     +---> MAINFEST.MF
   com
     |
     +---> companyname --> projektname --> my classes
    
    
I don't know where to place the resources. How can I handle and solve this problem?
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
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:
http://www.cokeandcode.com/index.html?page=tutorials/webstart

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:

1  
2  
      URL introURL = TutorialFramework.class.getResource(
            "images/classicClouds.JPG");


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:
http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html
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.

"It's after the end of the world! Don't you know that yet?"
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.

PocketCrafter7 (11 views)
2014-11-28 16:25:35

PocketCrafter7 (6 views)
2014-11-28 16:25:09

PocketCrafter7 (6 views)
2014-11-28 16:24:29

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

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

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

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

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

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

Gibbo3771 (27 views)
2014-11-24 19:59:16
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!