• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAR files dont like me...  RSS feed

 
Chut Murza
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!