📜 ⬆️ ⬇️

A simple java web application installation (part 2)

In fact, it’s not Java anymore. 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 can be that it pleases - jetty + your war, apache plus php-ha - in this case it does not matter anymore. It is important that this "something" - that you need to run as a service after installation

How to do it using WiX under the cut

image
')


Possible alternatives


Before we start dancing with a tambourine around WiX - I consider it my duty to tell you about the alternatives that I considered - and which, perhaps, will 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 cooker and check the “Web application” checkbox - voila - 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).

And it's a pity - in principle, this program did exactly what is 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 made comfortable wizards. Automatically add jetty - can not - so it must be done by yourself (for example, as described in the first part).
For Java programs, you can add such features as automatic checking of the installed Java version, automatic downloading and installation of it if necessary.

The free version can do a lot - and as I said - relatively easy to use, but - installing the service - only starting with the version of "Profi" - which costs $ 249 (I do not consider the options for ideological reasons).

In general - if you have $ 249 - you can not continue to read. I also felt sorry for spending this money on the condition that I didn’t need other features of the Profi-version - and it seemed to me to go over 250 bucks just to create a 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 a sign - if I'm not mistaken - this is the first project that Microsoft put into Open-Source and uploaded to 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 focus on it in more detail.

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

So - let's go

Once again about the requirements for installation


Refresh once again what we want from the installer:


Of course, I would also like a lot of things - automatic installation of JRE in the absence of it, configuration of the port on which the service is running, etc., etc. But - this is evident in the next version - so far the simplest installation of the service

First WiX file


Hmm ... unfortunately I did not find a way to insert the source code in the xml habrapost - it corrupts them very much: (
Therefore it is necessary to give links to the original article (written in English some time ago) - with comments here.

So, the simplest wix file with which we start working 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 - with the name of your product - and EmDev Limited - with the name of your company - the first cap is ready. This is not yet a real installation, but here we are:

Zaryat your classes


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

Folder Dances


Now we need to say what we want to deliver. It would seem - what is simpler - pointed to some directory and said - that's all, along with the subdirectories - I want to see in the installation (the programs described above do just about the same). But - alas, WiX apparently provides a fairly low-level interface to the Windows Installer, so it does not know how.
As I understand it, the installation contains several components (logical), each component may contain several files - but not folders (illogical - at least for me). Therefore, for each directory in your installation a separate component should be created for which a separate GUID should be set and so on and so forth (have not yet fried your classes ??? it's not too late to do this - unless of course you do not 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):
#PathToWix\tallow -dc:\Path\To\Your\Distro > tallow.wxs

where PathToWiX is the path where you put WiX, and c: \ Path \ To \ Your \ Distro is the path where the files you want to put into the installation are located
As a result, you will get a file similar to this one.
Now you just need to progenerate the GUIDs and insert them instead of all PUT-GUID-HERE (why tallow can't do this with a machine - I don't understand!) And insert all the 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)

Feature Description


One MSI can install several features that include a number of components. In our case, we have one feature - and we need to describe it after all the tags of the Directory - where we need to put all the components that we got tallow. Something like that

Well, that's all - the first installation is ready - we create MSI:
# candle emforge.wxs
# light -out EmForge.msi emforge.wixobj

We start it - without any questions, everything should be put - and then (if necessary) leave.

Setting service and links


Now we will configure the installation so that it configures and starts the service. To do this, put Jetty-Service.exe into a separate component and list 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 installation of the service should be started, and during uninstallation - stop and delete.
As a bonus, IniFile will create links wherever you want.

More GUY


In order for the installation not to look so short - add a GUY to it (don't get me wrong) - an example is shown here
And collect msi with
# candle EmForge.wxs
# light -out EmForge.msi EmForge.wixobj PathToWix\wixui.wixlib -loc PathToWix\WixUI_en-us.wxl

(in fact, everything is much the same as C ++ - candle - compiler, light - linker, wxs - source, wixobj - objectnik, wxl - lib)
And your installation will cease to be so bastard!

License


It’s quite a natural desire to replace the license that wix shows by default with something different - everything is simple - put the License.rtf with the text you need in the same place as the other files - and light will pick it up

Total


Well, almost everything. If everything is done correctly, the received msi should perform 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 for something more useful)

If something is not clear - you can always ask questions - I will try to help. Can be used as an example wix-file EmForge-a - the full source is here

Source: https://habr.com/ru/post/55503/


All Articles