Results 1 to 6 of 6
  1. #1
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default distributing a DB in a .jar file

    I have a program (called Flash) that makes use of a Derby embedded database. It works great.

    I want to package the program and database into a .jar file.

    I create the .jar file with:

    jar cvfe Flash.jar Flash *class images/* flashdb/*

    where the images directory contains .jpg files used in the program and flashdb is the Derby database.

    The .jar file is created just fine. When I click on the .jar file, it opens fine, displays the images, etc. But when I try to access the database itself, I get an error that the driver can't be found.

    My problem seems very similar to one posted by "hunterbdb" on 12-29-2008. I have read the tutorial on "Packaging Programs in JAR Files", but it doesn't seem to help.

    I'm wondering if this problem is akin to accessing image files, where I have used a construct like:

    URL appURL = getClass().getResource( "images/chalkboard.jpg" );
    Image appImg = Toolkit.getDefaultToolkit().getImage( appURL );
    ImageIcon appLogo = new ImageIcon( appImg );

    I appreciate any help anyone can give.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: distributing a DB in a .jar file

    The database library jar needs to be on the classpath, if you run the jar and get a ClassNotFound exception, this is the most typical cause

  3. #3
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default Re: distributing a DB in a .jar file

    When I create a manifest for the .jar file to set the class path

    Main-Class: Flash
    Class-Path: "C:\Program Files\Java\jdk1.7.0\db\lib\derby.jar;."
    (blank line)

    the .jar file can't find the the main class in Flash.

    When I remove the Class-Path line from the manifest, it runs fine, but the database driver can't be found.

    Is there some special formatting for the manifest when more than one header-value entry is used?

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,757
    Rep Power
    19

    Default Re: distributing a DB in a .jar file

    The format of the "classpath" in a manifest is not the same as when running a non-executable-jarred app.

    You just need to list all dependent jars (including their location).
    In your case I'd distribute the app with the derby.jar in a lib directory, since there's no guarantee the jar exists.

    If you just want it on your machine, then you just need C:\Program Files\Java\jdk1.7.0\db\lib\derby.jar, possibly in quotes (no idea about escaping for this sort of path).

  5. #5
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default Re: distributing a DB in a .jar file

    I'll give it a go, and let you know how it worked out. Thanks.

  6. #6
    newbie123 is offline Member
    Join Date
    Nov 2009
    Posts
    90
    Rep Power
    0

    Default Re: distributing a DB in a .jar file

    Thanks for your help Tolls and doWhile. The problem seems to have revolved around classpath specification under Windows.

    Case closed.

Similar Threads

  1. Distributing a project to another mac
    By madroadbiker in forum New To Java
    Replies: 6
    Last Post: 05-01-2011, 08:16 PM
  2. Replies: 5
    Last Post: 12-12-2010, 07:04 AM
  3. Distributing .jar
    By mine0926 in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 02:37 AM
  4. Weird problem with distributing .jar
    By Cynot in forum NetBeans
    Replies: 3
    Last Post: 06-07-2010, 10:01 PM
  5. Weird problem with distributing .jar
    By Cynot in forum New To Java
    Replies: 4
    Last Post: 06-07-2010, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •