How to create installer once finished with Java Desktop Application with MySQL DB?

12,328

Solution 1

  1. Yes. You can use some setup builder, like InnoSetup, for example. Personally, however, I like giving my customers a zip file, which they extract wherever they like. The executable jar should be able to handle everything by itself (I like it where there is no need to install the software, just unpack and run).
  2. If it is hardcoded, then yes (but, what do you mean by hardcoded? path to file? ip address?). You should use properties or configuration files for paths and other external things your software depends on. The software should read from those files. Upon startup check for presence of such file(s) - if missing, the user should be shown a window in which the config can be entered.

As for deploying MySQL with your code - consider using a server for that, so that your users are not forced to install MySQL, instead they connect to it over the net. If you need the database only for storing data locally, why not using SQLite or a similar, file-based db engine?

The above answers are just suggestions and more-less reflect the way I am thinking. I would be happy to hear from someone with more experience. Nonetheless, I hope the answers help a little :)

Solution 2

I agree with Sorrow.

If I have to use MySQL, it is normally over the net since I don't want to allow my clients pass through the hazzles of installing MySQL themselves. If however you am stuck with using MySQL locally, investigate MySQL unattended installations + NSIS Installer.

If you can use any db you want, I just use javadb/derby. It comes bundled with most Java installations these days and if not all you need is to add a jar file to you application.

As per 'hardcoding' paths, I really don't understand what you mean. You really don't have 'paths' as it were, I am assuming what you mean is connection string. You don't have to hardcode your connection string, just put some parameters in a properties file and construct your connection string from them.

Solution 3

1) Is there a way I can create a setup file that also installs the database and the application together?

See my answer to Java based Standalone application.

2) Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?

Have the DB installer pop a JFileChooser to ask the user where they want to install the DB. Store that path using the JNLP API PersistenceService. Here is my demo. of the PersistenceService.

Share:
12,328

Related videos on Youtube

Saher Ahwal
Author by

Saher Ahwal

Software Engineer at Microsoft LinkedIn Profile MEng Thesis: Optimizations to a massively parallel database and support of a shared scan architecture

Updated on May 31, 2022

Comments

  • Saher Ahwal
    Saher Ahwal almost 2 years

    I have finished writing a Java Desktop application with a mySQL database. I want to make the application run outside netbeans and let it be installed on other computers. I know about building the project and creating the runnable jar file, however this requires me to export the database itself to the other computer I want the application to run on. My question is two parts:

    1)Is there a way I can create a setup file that also installs the database and the application together?

    2)Also my database path is hard coded, does that mean I have to change the code every time I install my application for someone, what is the better way to do that?

    Thanks

  • Saher Ahwal
    Saher Ahwal about 13 years
    it's the url, it is on localhost 3306 should I just keep it this way and install mySQL for my client for fast installation?
  • Miki
    Miki about 13 years
    This falls into storing the data locally, you might want to consider SQLite which - to me - is a better idea. However, if you really want to stick with MySQL, then the url, port, username and password should be kept in some config file (password, obviously, somehow encoded, so it is not stored plain). That of course means each of your clients must have MySQL installed. Eventually, if in a local network, set up MySQL server on one machine and let other connect to it. This way you will not have to install clients for all of your users, but just one.
  • Saher Ahwal
    Saher Ahwal about 13 years
    Thanks alot, but one more question: regarding the first question I asked, do you create a zip of the whole project? I don't want the client to have access to the java code however, but the jar folder itself doesn't work?
  • Miki
    Miki about 13 years
    The jar can contain only the compiled, .class files. Then, the .zip file should have only the jar(s), documentation, external libraries, etc. No need to include source if you do not want to; once the code is compiled, it can be moved around computers and platforms. While it is possible to reverse-engineer .class file, the resulting code will be basically unreadable.