Transferring read-only databases to archive (jar or zip) files

Once a database has been created in Derby, it can be stored in a jar or zip file and continue to be accessed by Derby in read-only mode. This allows a read-only database to be distributed as a single file instead of as multiple files within a directory and to be compressed. In fact, a jar or zip file can contain any number of Derby databases and can also contain other information not related to Derby, such as application data or code.

You cannot store the derby.properties file in a jar or zip file.

To create a jar or zip file containing one or more Derby databases:
  1. Follow the instructions for creating a database for use on read-only media. See Creating and preparing the database for read-only use.
  2. From the directory that contains the database folder, archive the database directory and its contents. For example, for the database sales that lives in the system directory C:\london, issue the command from london. Do not issue the command from inside the database directory itself.

For example, archive the database folder and its contents using the JAR program from the JDK. You can use any zip or jar tool to generate the archive.

This command archives the database directory sales and its contents into a compressed jar file called dbs.jar.

cd C:\london
jar cMf C:\dbs.jar sales

You can add multiple databases with jar. For example, this command puts the sales databases and the boiledfood database (in the subdirectory products) into the archive.

cd C:\london
jar cMf C:\dbs.jar sales products\boiledfood

The relative paths of the database in the jar need not match their original relative paths. You can do this by allowing your archive tool to change the path, or by moving the original databases before archiving them.

The archive can be compressed or uncompressed, or individual databases can be uncompressed or compressed if your archive tool allows it. Compressed databases take up a smaller amount of space on disk, depending on the data loaded, but are slower to access.

Once the database is archived into the jar or zip file, it has no relationship to the original database. The original database can continue to be modified if desired.

Related concepts
Accessing a read-only database in a zip/jar file
Databases on read-only media and DatabaseMetaData
Related tasks
Creating and preparing the database for read-only use
Deploying the database on the read-only media
Accessing databases within a jar file using the classpath