0

I created a fat jar file using JarSplice, but when I launch it i get a window (the size is okay) and it closes after half a seccond...

In the "add jars" section I'm adding the jar file that I exported from Eclipse, and all library jars that I'm using. In the natives section I'm adding only Windows natives for lwjgl. I think I wrote the correct main class.

What am i doing wrong? How can I fix this problem?

Note: I'm using the newest version of eclipse and jdk.

Antimony
  • 2,230
  • 3
  • 28
  • 38
Qualphey
  • 1,244
  • 1
  • 19
  • 44
  • See the responses to this question http://stackoverflow.com/questions/9300116/executable-jar-file-not-running – Rajesh J Advani Aug 24 '12 at 20:28
  • 3
    Run the jar from within the command prompt instead of double clicking. That way the error message will stick around and you can see what's going on. Do this with `java -jar myjar.jar` – digitaljoel Aug 24 '12 at 20:28
  • thanks! I get an NullPointerException in this line `File[] files = new File("res/Models/" + dir).listFiles();`. Everything works fine when i run my game in eclipse. Maybe I can't load files like that? Or maybe eclispse doesnt export my res folder? – Qualphey Aug 24 '12 at 20:36
  • Just opend my .jar file with 7-zip, and i found res folder with all needed content. – Qualphey Aug 24 '12 at 20:37
  • I don't think that line can give you a `NullPointerException`. (Mind you, I'm not saying it'll *work*; but in the worst case, it should just set `files` to `null` if it turns out that that directory doesn't exist.) Maybe the line-numbers don't line up between your stacktrace and what you see in Eclipse? – ruakh Aug 24 '12 at 20:38
  • It does! I think it gives me this exception because it cant file that directory – Qualphey Aug 24 '12 at 20:42
  • I dont get any errors in eclipse, and everythiing works just fine – Qualphey Aug 24 '12 at 20:43
  • 1
    @ruakh It definitely could give a NPE because of the `.listFiles()` call. You might have missed it because of the word wrap in the comment. – digitaljoel Aug 24 '12 at 20:44
  • @digitaljoel: Not true. In Java, `new File("res/Models/" + dir)` will either return a non-`null` reference (to a newly-created instance), or else will raise an exception. It cannot return `null`, so it cannot cause `.listFiles()` to raise a `NullPointerException`. – ruakh Aug 24 '12 at 20:56
  • @ruakh My mistake, you are correct. – digitaljoel Aug 24 '12 at 21:40

1 Answers1

2

The file no longer is really on the "file system" but is instead in the jar, so you will need to load the resource from within the jar. When you run from within eclipse it is still on the file system, but when you create the jar it's not, that's why it works in eclipse but not when you package it up. The answer to this question should give you a good start on loading a file within a jar as a resource. That said, I'm not sure if you can do something similar to your listFiles call.

Community
  • 1
  • 1
digitaljoel
  • 26,265
  • 15
  • 89
  • 115
  • You're right, but actualy it doesnt work with `listFiles` can you please help me with that? – Qualphey Aug 24 '12 at 21:01
  • I'm not sure there's an easy way for you to do it as a classpath resource. Since you are packaging the jar, you should know the names of the resources that are in there, right? Then you can get them by name as needed? – digitaljoel Aug 24 '12 at 21:43
  • Well there are hundreds of .smd files in that folder, and all together they make a map. It would not be nice to write lines to load each model – Qualphey Aug 24 '12 at 22:02