You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by David Leader <d....@bio.gla.ac.uk> on 2007/10/26 10:13:06 UTC

Including a derby db within the same jar as the application ( was Including a derby database in a Windows executable)

John Embretsen replied to my query about packaging a derby db in an  
exe file:

 > If your database is read-only, I guess you could put your database
 > in a jar (your application jar file) and the wrap the jar in an exe
 > file
 >

To my embarrassment, I wrote last night:

> I tried that last summer when we were first playing with derby, and I
> gave up as I was unable to find a path to the database.

and gave examples of my feeble attempts.

And then at breakfast this morning  I realized that perhaps I should  
reference the application jar file itself (for some reason that  
didn't seem right to me):

jdbc:derby:jar:(MyApp.jar)MyDB

That works a treat. (And, obviously, it's not Windows-specific - so I  
changed the subject again.)

Perhaps an example of this sort might be included in  a future update  
of the derby developer docs - others might want to package a db in an  
app.

Thanks again for all the help from list members.

David


Re: Including a derby db within the same jar as the application ( was Including a derby database in a Windows executable)

Posted by John Embretsen <Jo...@Sun.COM>.
David Leader wrote:
> jdbc:derby:jar:(MyApp.jar)MyDB
> 
> That works a treat. (And, obviously, it's not Windows-specific - so I 
> changed the subject again.)

Thats great! I was just preparing an answer to your previous mail, with a 
different solution - so we are all learning here :)

Your solution references the jar file itself, and is particularly useful in 
cases where the database is in a different jar (or zip) than the application 
accessing it. I'm wondering if it might fail in some corner cases (e.g. if the 
working directory of the JVM is different from the directory where MyApp.jar is 
located), but I haven't tried it out.

An alternative solution, which is also described in the Developer's guide (under 
"Accessing databases within a jar file using the classpath"), is to not worry 
about the jar file name but just assume that the database is in the classpath.

The URL could for example look like this:

jdbc:derby:myDatabase

or (to avoid ambiguity) this:

jdbc:derby:classpath:myDatabase

(The database was added to the application's jar using
"jar uf MyApp.jar myDatabase/" )

> Perhaps an example of this sort might be included in  a future update of 
> the derby developer docs - others might want to package a db in an app.

I just went through the docs and agree that they should include more examples.
Feel free to open a Jira issue for this. I might even do so myself if you don't...


-- 
John