Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (778)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 2656 times)
0 Members and 1 Guest are viewing this topic.
Offline KONI

Junior Devvie

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


3. I read a properties file using:

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

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 Devvie

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) {
return this.getClass().getResourceAsStream(fileName) );
   catch(IOException e){}
   return null;

Read prop

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 Devvie

in code we trust

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

Yep, what Backmask said :-)
Here is a good overview of webstart:

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

JGO Coder

Medals: 1

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

Yep, what Backmask said :-)
Here is a good overview of webstart:

Good luck!   //

Should now be:

(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 Devvie

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:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<jnlp codebase="http://localhost/dactylo/"
    <title>Dactylo version 0.2</title>
    <vendor>Laurent Haan</vendor>
    <description>Dactylo Game for myschool</description>
    <j2se version="1.1+"/>
    <jar href="dactylo.jar" download="eager"/>
    <jar href="lessons.jar" download="eager"/>
  <application-desc main-class="dactylo.Dactylo"/>

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

Did I miss something ?

Thanks a lot !


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 Devvie

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 Devvie

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  

hadezbladez (377 views)
2018-11-16 13:46:03

hadezbladez (198 views)
2018-11-16 13:41:33

hadezbladez (380 views)
2018-11-16 13:35:35

hadezbladez (93 views)
2018-11-16 13:32:03

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

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

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

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

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

nelsongames (2337 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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!