Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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  
  Problem packaging .jar file  (Read 1282 times)
0 Members and 1 Guest are viewing this topic.
Offline KONI

Junior Member




Java games rock!


« Posted 2004-10-21 20:01:34 »

Hi there, I have some problems deploying my application with jar files, here's my directory structure:

1. /dactylo/ - here reside every .class file
2. /data/ - text files with data in it like the properties file
3. /data/lessons - text files with lessons needed
4. /gfx/ - all the images are in here


My program is packaged in "package dactylo;" and when I start my program in eclipse, everything works fine.

I got the following methods accessing components outside the package:

1. I read the content of /data/lessons with:

File dir = new File("data/lessons");

2. I read several images all using

Toolkit.getDefaultToolkit().getImage("gfx/image_name");

3. I read a properties file using:

properties.load(new FileInputStream("data/dactylo.properties"));



My question is, when I package everything inside a .jar file, the images won't load, the File returns a NullPointerException and the property file doesn't load. I know there is a problem with relative filenames and stuff but I don't know how to resolve the problem.

When I copy the folders data and gfx to the jar file, everything works fine, but I want to use webstart to deploy my software and as I know, everything has to be inside jar files to actually make them load.

I'd really appreciate every help I get  Cheesy
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #1 - Posted 2004-10-22 04:53:48 »

Use this.

 //Load image using ImageIO
 public BufferedImage loadImage(String fileName) {
   try{
return ImageIO.read( this.getClass().getResourceAsStream(fileName) );
   }
   catch(IOException e){}
   return null;
 }

Read prop
properties.load(this.class.getResourceAsStream
("data/dactylo.properties"));

If you need to read a dir in a jar file you need to use GzipInputstream to read the zip file and iterator all entries in the directory of the zip file. Search the forum for some code on that.

Offline gregof

Junior Member




in code we trust


« Reply #2 - Posted 2004-10-22 05:09:08 »

Yep, what Backmask said :-)
Here is a good overview of webstart: http://grexengine.com/sections/externalgames/articles/Kevin%20Glass-A%20Walkthrough%20with%20WebStart-JNLP-1.html

Good luck!   //
                      Gregof
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2004-10-22 06:21:11 »

Quote
Yep, what Backmask said :-)
Here is a good overview of webstart: http://grexengine.com/sections/externalgames/articles/Kevin%20Glass-A%20Walkthrough%20with%20WebStart-JNLP-1.html

Good luck!   //
                      Gregof


Should now be:

http://javagamesfactory.com/articles/Kevin%20Glass-A%20Walkthrough%20with%20WebStart-JNLP-1.html

(both point to the same place)

Also, there will be a major rewriter of that article done at some point. I think Kev's too busy, and it might not be until Xmas, so don't hold your breath Smiley

malloc will be first against the wall when the revolution comes...
Offline KONI

Junior Member




Java games rock!


« Reply #4 - Posted 2004-10-22 08:24:56 »

Thanks a lot for the great answers, I only got 1 little problem left.

I've got my application working using webstart and everything works just fine. When i start the .jnlp file localy, everything works just as expected.

But when I upload it onto the server, the following happens:

I use this code to read the jar file:

FileInputStream fis = new FileInputStream("lessons.jar");

when I start the .jnlp localy, the jar file is read and everything is ok.

When I upload it, he can't seem to find the .jar file.

I used the following .jnlp file:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<jnlp codebase="http://localhost/dactylo/"
href="http://localhost/dactylo/dactylo.jnlp">
  <information>
    <title>Dactylo version 0.2</title>
    <vendor>Laurent Haan</vendor>
    <description>Dactylo Game for myschool</description>
    <offline-allowed/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <j2se version="1.1+"/>
    <jar href="dactylo.jar" download="eager"/>
    <jar href="lessons.jar" download="eager"/>
  </resources>
  <application-desc main-class="dactylo.Dactylo"/>
</jnlp>


I am running a local apache and added the MIME type for the .jnlp file.

Did I miss something ?

Thanks a lot !

Update:

I changed the code a bit and now I can put everything in a single .jar file called dactylo.jar.

Everything works just fine now, but I've got the same problem as above. When I write:

JarFile jarfile = new JarFile("dactylo.jar");

then he can't find the file dactylo.jar when I start it on the webserver.

Any idea ?
Offline gregof

Junior Member




in code we trust


« Reply #5 - Posted 2004-10-22 10:58:07 »

You can't have a FileInputStream, it tries to read from a file on disk, when you use webstart you have to read all your resources as streams, like in the image-example above, try: InputStream fis = this.getClass().getResourceAsStream("/lessons.jar");

//  Gregof
Offline KONI

Junior Member




Java games rock!


« Reply #6 - Posted 2004-10-25 09:21:02 »

Thanks a lot for all your kind words and your help, now everything is working just fine.

Thanks !
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (14 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (60 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!