I have spent the last few months developing an application in java. It is being released under the Gnu Public License(GPL).
When I was developing it, a lot of the variables were compiled into the application. This includes things like the password and username for the database the application should access data.
The finished version will allow users to chose which database to use (MySQL, PostgreSQL, firebird). This is where the problem lies. Although the variables like the username can be put in a configuration file, to allow the choice of database the choices have to be loaded depending on which one should be used.
As I have all the databases installed for testing, as well as the JDBC drivers, this does not cause any problems BUT for it to be recompiled after changes are made somewhere else, the person compiling it would need all the JDBC drivers mentioned in their classpath or the compiler stops.
As the JDBC drivers are bigger than my application, I do not want to distribute them nor do I wish to hava a different version for each kind of database.
I also considered having the installer recompile the file without the unused databases, but this is not possible as not all users of the application will have a compiler.
My questions boil down to:
Although it is not safe, is there a way to make the compiler ignore the JDBC drivers it can't find?
Is there another way round the problem that not all users will have the JDBC drivers?
There's a few ways to make it ignore the missing JDBC driver, the basic being put a try/catch block around the area that loads the driver. A better solution might be to check for the existing of the class that would be missing if the driver was not installed in that this avoids throwing an exception. Although you couldn't proceed with database work after this, you could display a more meaningful message to the user or allow them to select a different database.
Unless you're going to write your own JDBC driver, I don't see a solution around the users not having the drivers installed in the general sense. Your application could detect likely JDBC drivers ahead of time and only allow support for those that have valid drivers.
Note that if your application fails to compile when the JDBC drivers aren't present, then you're using JDBC incorrectly! The only driver-specific text should be the Driver class name as a String, and that can easily be read from a configuration file. You can let the user choose the database just by editing the configuration (provide an interface for that if you like).
Do you mean that it can't "run", or really that it can't compile? Can you show us what won't compile?
Enclosing the loading of the drivers in try/catch blocks should be working.
To Ernest Friedman-Hill:
The only driver specific lines I thought I had is the String with the driver name in it, I'll look over everything again. Thinking about it after having a rest I realise it should be working as is. I will have another look.