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  
  How can I bundle a jar?including /res folder into thefinal jar using any bundler  (Read 1751 times)
0 Members and 1 Guest are viewing this topic.
Offline abe_no_i

Junior Newbie

« Posted 2012-08-05 13:27:15 »

I want to export my eclipse opengl project and this is working so far. But using jarsplice to bundle all libraries, natives and the main method to one final *.jar doesn't work: the /res folder (including *.png's and a 3dmodel cant be included into that *.jar.

Does anyone know a solution that esults in ONE *.jar with included data?

Thanks very much...
Offline Oskuro

JGO Ninja

Medals: 77
Exp: 10 years

Coding in Style

« Reply #1 - Posted 2012-08-05 13:35:26 »

Within Eclipse, right click on the project, select Export..., choose either Jar or Runnable Jar, tinker with the options and export to your chosen path.

Then open the .jar with a zip manager, and see if you like the result.

In case you're wondering, Runnable Jar only means that the Manifest declares the entry class.

There are more robust methods using command line, or MAVEN/ANT, but there are tutorials aplenty online for that, just keep this in mind: It looks harder than it really is.

Offline kappa
« League of Dukes »

JGO Kernel

Medals: 123
Projects: 15


« Reply #2 - Posted 2012-08-05 13:40:40 »

I'm guessing that you are using Java's File to load your resources, when loading resources from inside a jar you can't you use File and need to use an InputStream.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Ninja

Medals: 77
Exp: 10 years

Coding in Style

« Reply #3 - Posted 2012-08-05 14:40:26 »

I had issues loading resources from within the .jar once too, and this post helped:

From Stack Overflow:

It sounds like you're then trying to load the resource using a FileInputStream or something like that. Don't do that: instead of calling getResource, call getResourceAsStream and read the data from that.

(You could load the resources from the URL instead, but calling getResourceAsStream is a bit more convenient.)

EDIT: Having seen your updated answer, it seems other bits of code rely on the data being in a physical single file in the file system. The answer is therefore not to bundle it in a jar file in the first place. You could check whether it's in a separate file, and if not extract it to a temporary file, but that's pretty hacky IMO.

Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

nelsongames (2313 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!