开发者

Creating an installer for Java program with database

开发者 https://www.devze.com 2023-03-18 20:21 出处:网络
Recently I made an application in using Swing, AWT and JDBC that manages some database. I used PostgreSQ开发者_Python百科L as the backend with JDBC drivers to connect to the database. What I want to d

Recently I made an application in using Swing, AWT and JDBC that manages some database. I used PostgreSQ开发者_Python百科L as the backend with JDBC drivers to connect to the database. What I want to do is create a setup/installer program so that the application can be installed and used on any pc. My problem is I dont know how to integrate the database along?

Any help would be appreciated.


Take a lesson from most commercial applications that have a database component. Usually they require that the database be installed/configured beforehand and provide db scripts for their supported vendors. There are a lot of reasons for this. Most of these are related to the fact that organization's like to manage their own databases. This is often because they have company restrictions regarding security, maintenance, etc. Also a single database process may be shared between many different programs(if you install two instances of your application do you want to have to two installations of the database?).

Most folks(especially network admins) wouldn't want an application that ran around installing rogue DMBS's on their machine.

I wouldn't spend a ton of time attempting to install the database during your install process. Why re-invent the wheel when the vendor has already created an installation process for you? Instead install the database ahead of time and focus your installer instead on running the necessary scripts such that your application can connect to it on the first start up. What it does means is having your installer have the necessary drivers, connection information, and credentials to communicate with the database to get it initialized. After the DB is initialized then you can have additional routines that configure your application install such that it points to the database you initialized during the install. Taking this approach will not only be easier, but it will allow your application to do more interesting things like connect to remote databases or skip database initialization all together and connect to an existing database.


Writing an installer that also manages DB installation is a project in and of itself. The big question is do you need to install PostgreSQL from scratch or will you tell the user to install it themselves first?

I have attempted to do something similar and what I eventually did was build an installer with NSIS that includes Postgres and a JRE in the install bundle along with my program. The installer copies everything to the user's install location and creates all the required config files.

The biggest issue I had was that I had a number of config options to present to the user that would have taken a lot of programming in NSIS. So, I modified the ANT build scripts I already had written to build the project. What NSIS does then is copy the JRE to a temp location and start a Java installer GUI I wrote instead that gathers up all the config info and launches ANT in the background.

If you don't have much to configure or what you need to configure doesn't have many options, then you can probably do everything in NSIS directly. But, keep in mind that you need to be security conscious too. How are you creating a new user to run Postgres? What about directory permissions for you install? Who can start and stop the DB, who can read the db files, etc?


Maybe you may try a pure java database, like hsql, or h2, or derby....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号