• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing resources in a JAR

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic