So, you wrote your super web application in Java and now you want as many people as possible to download it, get it and start using it? Everything is fine, only for some java-programmers, especially for those who have lived in the J2EE world for the last two years, it may be a discovery that for 99.9% of people in this world the words “Just cover this WAR-nick on your favorite server” turn out to be a hollow sound. Well, ok, maybe not 99.9% and 99.8% - well, or so.
The following is the first part of the tutorial on how to make a beautiful Windows Installer out of your cook (yes, not only do most people not know the word warm, they also use Windows!) Using WiX
Formulation of the problem
So, we have:
- The web application itself is written in Java. In this case, it is assumed that the application is being built using maven (if you are not already doing this, I highly recommend it). As a result of the build, you get a war file (ok - not a full EAR - but for the EAR you just need to pack another server)
- It is assumed that this application runs under the server Jetty 6.0.x (if not - again - you just need to pack another server)
We want to create an installation of our application through
Windows Installer . During installation, you must:
- Do standard actions (ask where to install, show license, show progress)
- Install the application itself in the specified location
- Configure its launch as a service
- Add a link to the main page of the application on the Desktop (so that the user can easily access it)
')
What we will use:
All products are open source
Some moments may not be fully disclosed here - any questions and suggestions are welcomed. This solution is used to create an installer for the
EmForge project - this project is open-source, so a working example can be obtained from its sources (for example, via a web viewer:
www.emforge.org/browser/EmForge/trunk or simply by taking the source from svn repository
svn.emforge.org/svn/emforge/EmForge/trunk
In this part we will look at the process of creating a zip archive with an application ready to run.
So let's go ...
Packing the application with Jetty
First of all, we need to save the user from understanding the word Deploy. There are several possible solutions, for example, you can pack a simple server straight into a war-nick, as they do in Hudson (an interesting solution - but I haven’t figured it out yet). We will go the other way - and create a Zip-archive in which we put Jetty, configured to launch our war-nick.
The idea was taken from this blog:
blog.devspan.com/2008/02/creating-distributable-war-project-with.html - here I will describe only the main idea (if necessary - say - I'll
write it out in more detail):
- We have a web project collected by maven (http://www.emforge.org/browser/EmForge/trunk/emforge-web in our case)
- Create a new launcher project. The project structure and the required files can be simply copied from the emforge-launcher by finishing it with a file for your project: www.emforge.org/browser/EmForge/trunk/emforge-launcher
- We configure the maven-assembla-plugin project in this project to take the cooker and the required jetty libraries from the maven repository and put them in the “right” places
- First, run the mvn clean install in our web project, so that maven collects and puts our project in a local repository
- Then run the mvn clean assembly: assembly in the launcher project - as a result we will get the required zip
As a result, we get a zip in which will lie jetty and your application. The structure of the zip will be approximately as follows:
- etc Jetty
- jetty.xml
- jetty-win32-service.xml
- webdefault.xml
- lib , jetty
- wrapper.dll
- wrapper-3.2.0.jar
- jety-6.1.14.jar
- jetty-util-6.1.14.jar
- jetty-win32-service-java-6.1.14.jar
- servlet-api-2.5-6.1.14.jar
- start-6.1.14.jar
-logs
- webapps
- root
Jetty-Service.exe jetty
jetty-service.conf
Please check:
- jetty-service.conf should contain the name of your service. By default it will be Jetty - but you will probably want something else.
- also check that jetty-service.conf contains the correct paths to libs & logs
- In jetty.xml, check the port on which the service will be launched - by default it is 8080, but this port is very widely used and therefore it is better to use some other port.
- The root directory should contain your web application, that is, the WEB-INF directory should be directly under root
Well, that's all for now. In principle, this can and will stop - not a lazy user can already just download zip, unpack it and start the server with your application using run.bat or run.sh
We will talk about the solution for “lazy” users in the next series.