Simple Java Web Application Installation (Part 2)

    In fact, this is not about Java. Suppose you have some zip with some program (for example, created in the first part) - and you want to make msi for it (for installation through the Windows Installer). It could be something nice - jetty + your war, Apache plus php-ha - in this case it is not important anymore. It is important that this is “something” - that after installation it is necessary to run as a service.

    How to do this using WiX under the cut

    image



    Possible alternatives


    Before we start dancing with a tambourine around WiX - I consider it my duty to talk about the alternatives that I considered - and that may well suit you

    WItem Installer for Java

    Here www.witemsoft.com/forjava you can find a fairly simple and most importantly free program that can create an installer for your java-web application - just set it on your varnik and check the "Web application" box - voila - you get MSI which is all puts.

    One problem - it packs into the Jetty 4 distribution (the program is quite old) - which is very old and in my case did not allow me to run my application. I could not adequately fix this (the program is not open-source).

    But it’s a pity - in principle, this program did exactly what it needed - everything is simple and clear.

    Advanced Installer for Java

    Another candidate: www.advancedinstaller.com/java.html

    More difficult to use (but still quite simple) - but also much more powerful. Everything is done with convenient wizards. Automatically add jetty - does not know how - so you need to do this yourself (for example, as described in the first part).
    For Java programs, you can add features such as automatic verification of the version of installed Java, automatic download and installation thereof if necessary.

    The free version can do a lot - and as I said - it’s relatively easy to use, but - installing the service - only starting with the “Profi” version - which costs $ 249 (I don’t consider options for warez for ideological reasons).

    In general - if you have $ 249 - you can not read further. I was sorry to spend this money on the condition that I did not need other features of the Profi version - and it seemed to me overkill to pay 250 bucks only for creating the service

    What is WiX?


    So - WiX - wix.sourceforge.net - a set of command-line tools that allow you to create MSI from XML files
    A few words about this project. The WiX project is largely significant - if I'm not mistaken - this is the first project that Microsoft donated to Open-Source and put it on a hosting at SourceForge (yes! And it happens!). Unfortunately, there is very little information on the project and the dock - even less in Russian - because here I will dwell on it in more detail.

    The project is implemented on .NET - so we need windows (with mono I just did not try it) - and, alas, dear javists - .NET runetime .

    So, let's go

    Once again about installation requirements


    Once again, refresh what we want from the resulting installer:
    • First of all, put all the necessary files
    • Let the user choose where to put
    • Configure Jetty to run as a service
    • Run this service after installation and always do this at system startup
    • Put a link to our application on the Desktop and on Start - so that the user can easily launch the browser set up on our application
    • Well, so that everything is correctly deleted during uninstallation


    Of course, I would like to have a lot more - automatic installation of the JRE if there is no one, configuring the port on which the service is running, etc., etc. But - this is evident in the next version - for now the simplest installation of the service

    First WiX file


    Hmm ... unfortunately I didn’t find a way to insert the source into the xml hubpost - it corrupts them a lot :( (I will be glad to advise on how to do it correctly)
    Therefore, you will have to give links to the original article (written in English some time ago) - with comments here.

    So, the simplest wix file we will start working with is as follows: www.emforge.org/wiki/Windows+Installer+For+WAR#section-Windows+Installer+For+WAR-FirstWiXFile

    Put down the generated GUIDs instead of questions, replace EmForge - to the name of your product - and EmDev Limited - to the name of your company - the first stub is ready This is not a real installation yet, but here we are:
    • Defined the brew of our product
    • Defined the directory TARGETDIR - where we will put everything
    • Created EmForge daddy in "Start -> All Programs"
    • Defined directories for Desktop and Program Files

    Fry your classes


    As we will see later, WiX works quite oddly with directories. So - the fewer directories in your application - the easier it is for you. Plus, with further development, any movement of the folders can dramatically affect your installation. If we install a web application, then we have a lot of things in the WEB-INF / classes directory. I, like many other programmers - I like to make a “refactor” - moving classes from one package to another - and I absolutely do not want to think about it - how this will affect my installation. Because - just a friendly advice - pack all your classes with jar and put it in WEB-INF / lib - then with a clear conscience remove the folder WEB-INF / classes

    Folder Dancing


    Now we need to say - what do we want to deliver. It would seem - which is simpler - pointed to some directory and said - that's all, along with subdirectories - I want to see in the installation (the programs described above do something like this). But - alas, WiX apparently provides a fairly low-level interface in the Windows Installer, so it does not know how.
    As I understand it, the installation contains several components (logically), each component can contain several files - but not folders (illogical - at least for me). Therefore, for each directory in your installation, a separate component must be created for which a separate GUID must be set, and so on and so forth (your classes haven’t fried yet ??? not too late to do this - unless of course you want to set the GUID for each package)

    Fortunately, there is still some automation tool - this is the tallow program (included in wix 2.0): where PathToWiX is the path where you installed WiX, and c: \ Path \ To \ Your \ Distro is the path where the files that you you want to put in the installation As a result, you get a file similar to this Now you only need to generate the GUIDs and insert them instead of all the PUT-GUID-HEREs (why tallow cannot do this automatically - I don’t understand!) and insert the entire contents of the DirectoryRef tag ( without the tag itself) inside the ProgramFilesFolder tag and replace Directory0 with INSTALLDIR (this will allow us to choose the installation path during the installation tion)
    #PathToWix\tallow -d c:\Path\To\Your\Distro > tallow.wxs





    Feature Description


    One MSI can install multiple Feature, which include a number of components. In our case, we have one feature - and we need to describe it after all the Directory tags - where to put all the components that tallow generated for us. Something like this

    Well, that’s it - the first installation is ready - we create MSI: Run it - without any questions, everything should be installed - and then (if necessary) - leave.
    # candle emforge.wxs
    # light -out EmForge.msi emforge.wixobj



    Service and link settings


    Now we will configure the installation so that it configures and starts the service. To do this, take Jetty-Service.exe into a separate component and write its configuration in the same way as shown here and add a new component to the feature.
    Everything is obvious here (I hope) - ServiceInstall - the service installs, ServiceControl - says that the service needs to be started by the installation, and when uninstalling, it should be stopped and deleted.
    As a bonus, IniFile will create links wherever you want.

    Bigger GUYA


    So that the installation does not look so short - let's add GUYA (do not get me wrong) - the example is shown here
    and build msi using (in fact, everything is very similar to C ++ - candle - compiler, light - linker, wxs - source, wixobj - object , wxl - lib) And your installation will cease to be so ugly!
    # candle EmForge.wxs
    # light -out EmForge.msi EmForge.wixobj PathToWix\wixui.wixlib -loc PathToWix\WixUI_en-us.wxl




    License


    It’s quite a natural desire to replace the license that wix shows by default with something of its own - it's simple - put License.rtf with the text you need in the same place as the other files - and light picks it up

    Total


    Well, that’s all. If everything is done correctly, the resulting msi must complete all the tasks assigned. Ideally, it should not take more than 2-3 hours (and with a clear conscience you can spend the saved 250 bucks on something more useful)

    If something is not clear - you can always ask questions - I will try to help. You can use the EmForge wix file as an example - the full source code is here

    Also popular now: