• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing resources in a JAR  RSS feed

 
Dávid Kéri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I'm making an application, of which I would like to create a runnable jar file.

First, I used direct paths to access resources, like

but as I understand,this will not work (and indeed does not ) if the application is being run from a jar file.

Can I get some help on this matter? I tried to use URLs, but since this is an application, not an applet, getCodeBase() and such methods are of no use.
I really tried everything I could think of, so I would appriciate any help I can get!

Thanks!
 
Henry Mbadiwe
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just place the image in the jar file?
 
Dávid Kéri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting.

In the meantime I managed to do that. I'm working with Eclipse, and I used the export / runnable jar function.

Unfortunately, it has put all my images in the root folder of the jar file, although I clearly set that it should put it to the "output folder : images".

Any idea on this one?
 
Dávid Kéri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a new problem on this topic..

I managed to export my application into a runnable jar archive. Moreover, my image resources are loading properly as well. I used the following code to achieve that:



,where there is an "images" directory in the root folder of the JAR, and within it are my jpegs.

Now, I tried to reach my .db file and .obj files the same way, and it did not work....

here is the code:



This returns with a FileNotFoundException, when I start the JAR file. It works properly when I run it from Eclipse though.
I looked at the JAR file, and everything seems to check out, the path is correct, from root, there is a Fortress folder, etc and the .obj file is there too.

Same with the .db file:



,where the dbfile (fortress.db) can be found in the root of the JAR file. Still, there is an SQLException, saying no such table Fortress (thats inside the db file).


Any help in this please, Im completely stuck, tried everything.
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!