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

    Default understanding jar files and derby

    O.K. I've made some progress in deploying my Derby-based application in a .jar file.

    A new problem, however, has cropped up.

    I want to package the necessary driver (lib/derby.jar) and database (flashdb) along with my application (flash) in a .jar file (Flash.jar). To this end, I used the following command:

    jar cvfm Flash.jar Manifest.txt *class lib/* flashdb/*

    where the manifest contains the following entries:

    Main-Class: Flash
    Class-Path: lib/derby.jar

    As long as lib/derby.jar and flashdb are in the same directory as the .jar file, everything runs swimmingly. But if I move only the .jar file somewhere else, the program can't find the driver.

    If I view the table of contents of the .jar, the driver appears to be there.

    So the question (of the moment) is: How do I set the Class-Path so that it finds the driver (within Flash.jar)?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: understanding jar files and derby

    How do I set the Class-Path so that it finds the driver
    I don't think the java program will search for your jar file. You must specify where it is and leave it there.

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

    Default Re: understanding jar files and derby

    So, if I distribute the program, database, driver, etc. in a .jar file, I'll need to extract the database, driver, etc. before the program can access them? I composed a little .bat file to do this. It works, but it isn't very clean.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: understanding jar files and derby

    It depends. The java program is would be able to read .class files that are in the jar file.
    The OS would need the .dll type of files to be outside of the jar file as separate files.
    If the database can be accessed as a resource via a stream, it could be in the jar file. If the classes for accessing the DB only work with files, then the DB would have to be its own file.

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

    Default Re: understanding jar files and derby

    The proximate problem appear to be the inability to find the driver in derby.jar, which is part of the .jar file.

    What confuses me is that if I issue the command

    java -jar Flash.jar

    the driver is found, and the database is accessed just fine.

    Why should it also not work by just clicking on the .jar file?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: understanding jar files and derby

    The OS controls what happens when you click on a file to "open" it. The OS needs to have a commandline template like the commandline you used: java -jar <THEJARFILEHERE> with the name of the jar file being filled in when the OS tries to "open" the file. If the commandline is not set up properly, then the jar file does not execute.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default Re: understanding jar files and derby

    1. You cannot jar jars in an executable jar. Well, you can, but the JVM cannot access them when executing.
    2. Distributions should generally involve your jar and a lib containing dependent jars...after all, if there's a bug in a dependency then why deploy the whole thing? Deliver it as an installer or a simple zip.
    3. If you have a db in a jar it will be read only. If that's not a problem then OK, otherwise you'll need to provide that in your distribution as well.

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

    Default Re: understanding jar files and derby

    Thanks Norm and Tolls. This really helps clarify things. I'll just put everything in an installer.

    I am really glad this forum exists!

Similar Threads

  1. Derby Mystery..!!!!
    By yiantzi in forum JDBC
    Replies: 3
    Last Post: 01-24-2011, 11:59 AM
  2. Derby.jar
    By wulfgarpro in forum New To Java
    Replies: 0
    Last Post: 10-02-2010, 05:22 AM
  3. derby DB problem
    By edi.gotieb in forum Forum Lobby
    Replies: 8
    Last Post: 05-17-2010, 12:45 PM
  4. need some derby tips:
    By kulangotski in forum Advanced Java
    Replies: 4
    Last Post: 03-09-2009, 05:09 PM
  5. using if in derby
    By suhaib1thariq in forum JDBC
    Replies: 0
    Last Post: 01-25-2009, 04:46 AM

Posting Permissions

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