Creating an installer for Java program with database - java

Recently I made an application in using Swing, AWT and JDBC that manages some database. I used PostgreSQL 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....

Related

How to make a server for a Java and MySQL application

I created a Java application that accesses a MySQL database (made using MySQL Workbench). I want to create an installer for my application so that other users can use it on other computers, but I can't figure out how to do so.
I tried using Launch4j and Inno Setup Compiler, but when I tried to install the application on another computer it didn't access my database.
After a bit of research, I found out that I (maybe?) have to use a server for my database, but I couldn't figure out what and how to do that.
My questions are:
Do I have to use a server to make my application installable on other computers?
What is the easiest server to use for this task?
PS: I'm very new at programming so please be as explicit as you can :)

Porting Java/Mysql application from Linux to Windows

I have written an application in Java and used MySQL as the database system. The user can insert or delete the rows in database tables. I have developed the application on Ubuntu 11.10 and it is working properly.
My question is how should I port this application to a Windows machine? Do I need to install MySQL server on that machine? If yes, how to pack all executables into a single .EXE. How do I make this application work on all platforms?
Java applications, unless you did some less ordinary things such as relying on line ending or did JNI, should generally work OOB in all the platforms java is supported. Test and fix the things that don't work.
MySQL installations are different per environment, and yes, you'd need the DB server on that environment too, if you plan to run it locally. Usually, you'd request the user to install MySQL and configure it to your application - I see a potential EULA/TOS issue with packaging MySQL binaries with your own application. If you'd do it anyway, you'd want to use an installer to create an install file for you that would include the files and perform steps that are needed.
Edit: see this thread for more convenient alternatives than using MySQL with your software and also for a note about the potential license agreement issue.

Distribute Java application in Mysql

I wish to distribute my restaurant application, which uses MySQL to store the data. I plan to use Lauch4j to distribute its .exe file.
But the program also requires the user to have mysql Installed, is it possible to hard code mysql setup within the application? or anything else that could be done to avoid the user the pain of downloading and installing it?
It is a matter of opinion, but I advise you to not do it.
If your main concern is the install process being easy for the user, use some embedded DB. That way, the user not only will not have to care about things like firewalls, possible mysql vulnerabilities and so on.
If you need something that only mysql or other standalone DBs can provide you, don't hide it from the user. Technical capable users should be allowed to configure your app to run in the sql engines they already have installed (if they want to). Other people should at least know that you are installing something else apart of your app. Of course less tech-savy users will be scared, but if they do not know what they are doing they should not be tinkering with MySQL (or even installing programs).
In essence: Let the people know what you are installing in their systems. Allow them to reuse other DB engines if they chose to.
If i was you, if MySQL was the option, I would just take it for granted that it is installed and ask for the connection parameters (make it the first step of the installation procedure so you can check it before proceeding).
You can use SQLite in for your application. If any application needs to store data in the same system only and the application needs to be small and lightweight application then you can use sqlite as database. SQLite makes a great application file format.

Distributing java web applications

We have a java application hosted on JBoss with a Posgres DB, and we've traditionally been selling it as an appliance (full server with application installed). Now, we need to allow clients to be able to download and install it on their servers. What is the best way to approach this? Ideally, I'd like it to be a one packaged installation file that they can run and it checks for dependencies, deploys the war file, executes the postgres sql to setup the database and start up jboss.
JBoss and Postgres will be installed by the client prior to installation.
The simplest way is to use a bash script for Linux and possible bat/cmd files for Windows, though that is not ideal. Are there any libraries available to accomplish something like this?
install4j can be used to let users install applications. The installation package will contain everything needed (application, JBoss, postgres). Furthermore, it has ant and maven tasks, too, and you can even allow the users to do some basic configuration on-the-fly.
The latest version of JBoss is OSGi based. Have you consider to use this solution ?
If JBoss and Postgres are already preinstalled and configured by users as they wish then it would be very difficult to make a silver-bullet automatic installer that takes into account and correctly handles whatever incompatibilities it can face in real life.
Maybe a detailed install instruction would be enough. Especially for advanced users. For the others - bundle some diagnoctic scripts in case they face problem.
Also consider using liquibase to do automatic database initialization and migration on application's startup. This would greatly simplify the rest of install procedure: just check deps, make datasource and deploy app.

Create an installer in Java

I want to create an installer using Java that install at first MySQL. The user tape at first the password of root user. Then the installer copy jar file into program files and create shortcut on desktop.
So my question how to install MySQL automatic via Java. Is there any way??
Thanks in advance.
best regards,
Ali
Depends on the platforms you want to install onto. Basically if you know how to do it via the command line, then you can write a shell script that is executed from Java, or a series of command line statements that are executed from Java to do it.
Since you mention root user, I'm guessing some flavor of linux? Doesn't MySQL already have ways of doing this that come with the installers and/or binary distributions?
This write-up might help you in creating a java installer: Convert Java to EXE (also has information about other platforms)
But, before going for that, I would like to ask you, why do you want o bundle MySQL with your java app? The recommended way, if you want a DBMS bundled in your app can be:
Ask the user the install MySQL him self. You app will use it.
Use SqLite (embedded RDBMS). Or even simpler, Berkley DB for a Key-value store. This approach will be super light and no installation needed.
You can try to perform a 'private' ad-hoc MySQL installation that is only used by your application: that means you will have to copy the binaries (please note they are different for each platform) plus some custom configuration files to a 'mysql' subdirectory of your programs' main directory.
I can assure you it won't be easy and fast to do. You have to struggle a bit making it work under each platform. This kind of stuff is always a bit tricky.
If you prefer to install MySQL in a system-wide manner (as a service, using the provided install package) you'll have to embed the package into your setup program and then use the proper operating system commands to install it. That would be different on each platform, and under Linux you'll have to install the proper package for each distro. Messy.
You can look at some commercial solutions for making Java install programs. See install4j for example.
Shipping MySQL with your Java application is not so easy. Are you sure you need MySQL, and you cannot use some simpler alternatives, like sqlite? If you choose sqlite, there are some 100% java solutions, and that means no difference between platforms and easy deploy of your application.
Think about it, listening to this simple advice can make you save 14-15 hours of work and debugging (with always some possibility of failure, because complex installers do fail).

Categories

Resources