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)?
Re: understanding jar files and derby
Quote:
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.
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.
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.
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?
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.
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.
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!