• 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

JAR files dont like me...

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JAR file that contains all my executable code, as well as an embedded database file. The problem is that I can't get the jar file to read from the database file that exists inside of itself, like it isn't there at all. But it will work if the database file is in the same directory as the executable JAR... Now I have tried many combinations with the Classpath: attribute in my MANIFEST.MF file but still no luck... Does anybody have a clue on what to do? Any help or explanation will be tremendously appreciated!
Thanks,
Chuck
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chut,
When working with files stored in jars, you have to load them as uniform resources (URLS). To load the file you need to do something like this:

Hope this helps,
Michael Morris
 
Chut Murza
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael, your little snippet of code didn't do the trick but it certainly pointed me in the right direction. I tried many different things and the only thing I could come up with that worked was something very similiar to:

Now, everything did work as planned but I know there has to be an easier, more efficient way to accomplish this. I messed around with the classes in the java.util.jar package and no matter what I tried I could not grasp a reference to the RandomAccessFile that lay embedded in the .jar file. If anybody can figure out a simpler way to perform the same tasks I would be more than happy to listen!!!
Thanks,
Chuck :roll:
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have a JAR file that contains all my executable code, as well as an embedded database file. ...


It's odd that what I posted didn't work . Do you start the application with java -jar ? If so, then the ClassLoader should be able to pick up any resourse in the jar with class.getResource(path). Try this and see if it works:

That's assuming that dbFile.db is in the root of the jar. If it is not, then give a relative path instead of an absolute path (contrary to what I posted).
Michael Morris
 
What are you doing in my house? Get 'em tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic