• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Path to store Embedded Database files

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making an application with embedded database. This application will be Swing based and it will be a single jar file. So my aim is that everything should happen in the jar file.

Since I am using embedded database i want all my databse files ot be in the jar files. I am creating a folder/ package say "database" in "src" folder which will be home to all database related files.

NOw the problem is how do i define the path dynamically. Like consider the following case.

While i am creating the project the "database" folder will be in "home/project_name/src/database". But in the jar file this folder will be at "place_where_jar_file_is_located/database".

I used System.getProperties("user.dir") to get current working directory and i can go into src/database through it. But then in the jar the structure is different. SO the same won't work

I am getting confused in handling/defining the path.

How should I be handling it???

Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all you must consider what will happen when you add records to your database if your database file is stored within your application jar.

I would recommend that your database file should be located somewhere else, but in the application jar. As a matter of fact, (and somebody please correct me if I am wrong), I do not believe you can modified the contents of a file stored in a zip format, like a jar. Now, even though your file is read-only I would consider to put it somewhere else.

That being said, there are plenty of options to solve this problem. The first is to put the file in the same directory of your jar.

Then simply:


Another option is to pass the path to the directory of the database file in the java application launcher classpath:

java -cp myjar.jar; /home/obiwan/database/

Then simply:

InputStream in = ClassLoader.getSystemResourceAsStream("data.db");

Or you could pass the path to your file at the application start up

java -jar myJar.jar /home/obiwan/database/jedis.db

Or you could save the path to your file in a properties file and get it from it, or you ask in the GUI the path to the file (like in MS Access database).

Do any of these sound useful?
[ June 06, 2006: Message edited by: Edwin Dalorzo ]
Darshit Hirani
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Edwin.

AS a part of the application I need everything into one file so was wondering if it is possible.

Thanks for the other ways, if there is no way to put everything into one i will use one of the methods you mentioned.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!