16

How to create a installer using Java that combine tomcat, mysql and war file and come out a final exe?

Wilson
  • 163
  • 1
  • 1
  • 5
  • Do you think you could be a bit more specific, do you want the exe to install tomcat and mysql on the system or do you want it to be an exe that will run both tomcat and mysql as daemons or something? – Henry B May 13 '09 at 08:44
  • Yes, the exe installer need to install the tomcat, mysql, web application, and db script all in once. At the end, users only need to start the tomcat and mysql service. Go to browser can access the web application. – Wilson May 13 '09 at 09:15
  • Can someone please edit the question title to be a little more descriptive? ("How to create Java webapp installer (.exe) that includes Tomcat and MySQL?", or something.) Thanks. – Jonik May 13 '09 at 11:25

6 Answers6

20

You could use any installer, really. I personally have used InnoSetup, which is quite simple, but can still perform almost any task at installation time.

In your case, you probably want to place the Tomcat files somewhere, webapp included. Customize some configuration files and run the MySQL installer in silent mode. All of which is perfectly possible with InnoSetup.

If you need more flexibility, you can look at NSIS, another very simple but very powerful installer app.

Gerco Dries
  • 6,682
  • 1
  • 26
  • 35
  • 1
    Thank for ur recommendation..InnoSetup is good and easy to use. – Wilson May 13 '09 at 10:14
  • Someone posted a follow-up question about how to do this with Inno Setup: http://stackoverflow.com/questions/938925/how-to-use-inno-setup-to-create-an-installer-for-installing-the-tomcat-mysql-we – Jonik Jun 02 '09 at 11:25
9

The possible options have been largely covered in several questions already, especially:

...and other questions tagged java + installer

Although admittedly some options mentioned in those questions cannot produce self-sufficient .exe installers. If a commercial tool is ok for you, I can personally recommend install4j (costs $); among other things, it can create .exe installers (details about my experiences with it). Or, for a simpler, free tool for producing Windows executables out of Java programs, see Launch4j.

Update of my install4j recommendation, based on this comment by OP:

Yes, the exe installer need to install the tomcat, mysql, web application, and db script all in once. At the end, users only need to start the tomcat and mysql service. Go to browser can access the web application.

With install4j,

  • you can bundle Tomcat, MySQL and your webapp just fine
  • you can automatically start the services too from the installer (or leave it to users as you suggest)
  • if you want, the installer can even directly launch the browser and point it to your webapp :-)

I have just done a similar thing with install4j (bundle application server, webapp, run database scripts, and many other things; without bundling the database however), so I'm relatively sure it can be done. I do not know if you can do this (easily) with the free tools such as Launch4j.

Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372
  • -1 This isn't covered in any of the above. He is clearly talking about installation of tomcat and mysql with a WAR not a java application but a java webapp. – Henry B May 13 '09 at 08:45
  • Well, it has been covered to some extent, since for example with install4j you can include Tomcat, MySQL, WAR files or whatever you wish. – Jonik May 13 '09 at 08:53
  • I mean, if we're talking about creating .exe installers for Java software, the possible tools will be the same anyway, no matter if it is a web application or not. – Jonik May 13 '09 at 08:57
  • Only since your last update and still you center around installation of jars which is very different from what is being asked and it clearly isn't 'java software' is it? – Henry B May 13 '09 at 08:59
  • Nope, I never centered around installing JARs. If you look at e.g. install4j (http://www.ej-technologies.com/products/install4j/features.html), you'll see it can do pretty much anything, even if it's specifically geared towards installing Java software. If .exe installer is a requirement (as it seems to be), I still think the most appropriate tools will probably be ones I'm pointing to. – Jonik May 13 '09 at 09:09
6

Here is my minimalistic solution to this problem. I have downloaded tomcat and MySQL installations without installer, so I just unzipped them, and I tried them they work fine. At this moment you will install the war file to tomcat, and relevant schema to the mysql. So when you copy the folders everything is copied. And you can test how it works. Probably you can do some tune-ups on them, but for me they work just fine out-of-the-box, as my app is not that demanding. Apart from that I have downloaded both 32 and 64 bit version of programs so they can both be installed. I used Inno setup to pack the installer up. Basically it only copies both folders by choosing 32 or 64 architecture, and installs both, tomcat and mysql, as windows service.

[Setup]
AppName=MyApp
AppVersion=1.0
DefaultDirName={pf}\MyApp
DefaultGroupName=MyApp
Compression=lzma2
SolidCompression=yes
OutputDir=output   
; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
; On all other architectures it will install in "32-bit mode".
ArchitecturesInstallIn64BitMode=x64
; Note: We don't set ProcessorsAllowed because we want this
; installation to run on all architectures (including Itanium,
; since it's capable of running 32-bit code too).

[Files]              
; Install x64 if running in 64-bit mode (x64; see above), x86.exe otherwise.   
Source: "mysql-5.5.13-winx64\*.*"; DestDir: "{app}\mysql"; Check: Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs 
Source: "mysql-5.5.13-win32\*.*"; DestDir: "{app}\mysql"; Check: not Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs  
; Install x64 if running in 64-bit mode (x64; see above), x86.exe otherwise.   
Source: "apache-tomcat-6.0.32-x64\*.*"; DestDir: "{app}\tomcat"; Check: Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs 
Source: "apache-tomcat-6.0.32-x86\*.*"; DestDir: "{app}\tomcat"; Check: not Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs
;   
Source: "start.bat"; DestDir: "{app}"; DestName: "start.bat"; 
Source: "stop.bat"; DestDir: "{app}"; DestName: "stop.bat"; 

[Icons]    
Name: "{group}\Start MyApp"; Filename: "{app}\start.bat"
Name: "{group}\Stop MyApp"; Filename: "{app}\stop.bat"

[Run]     
; install mysql and tomcat as services
Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "--install MyApp_MySQL"
Filename: "{app}\tomcat\bin\service.bat"; Parameters: "install"   
Filename: "{app}\start.bat"; Description: {cm:LaunchProgram,{cm:AppName}}; Flags: nowait postinstall skipifsilent

[UninstallRun]   
; uninstall mysql and tomcat as services  
Filename: "{app}\stop.bat";
Filename: "{app}\mysql\bin\mysqld.exe"; Parameters: "--remove MyApp_MySQL" 
Filename: "set"; Parameters: "CATALINA_HOME={app}\tomcat"
Filename: "{app}\tomcat\bin\tomcat6.exe"; Parameters: "//DS//MyApp_Tomcat"

[CustomMessages]
AppName=MyApp
LaunchProgram=Start MyApp after finishing installation

In order to run your app now all you need is to start/stop registered services. start.bat

NET START MyApp_MySQL
NET START MyApp_Tomcat
START "" "http://localhost:8080/myapp/" 

stop.bat

NET STOP MyApp_MySQL
NET STOP MyApp_Tomcat

For me it works just fine.

  • Maybe you can include JRE installation as well, cause some comps might not have it.
  • Also if someone knows how to inspect if tomcat and mysql ports are already taken, and how to change them in conf file, please tell us.
  • Also if you can inspect the IP address and type it instead of localhost that would be great.

Regards

Amir

Amir Jamak
  • 61
  • 1
  • 1
1

I would suggest, that you use Java for this, a installer.jar. As you would like to run tomcat anyway, theres no need to put in a exe file. We've done something similar, programming an jar installer with the help of the Ant API (Ant used programmatically).

Mork0075
  • 5,895
  • 4
  • 25
  • 24
  • Can you give a bit more information on this, I'd like to know more about it and how it's done. – Henry B May 13 '09 at 08:45
  • Download the Ant jar from the Apache website and play a bit with the API. Instead of using perhaps the XML command u use a class Copy und run some methods. – Mork0075 May 13 '09 at 09:16
  • oh, I see what you mean. so you install it when you compile as opposed to deploying an installation to a client/server machine? – Henry B May 13 '09 at 09:23
  • Yes, the installer.jar can be downloaded from a Mercurial repository. After this the installer takes control, downloads the software (also from a repository), compiles and deploys it as a service. – Mork0075 May 13 '09 at 10:17
0

You can use BitRock InstallBuilder for it (costs $). For examples of such programs, checkout Alfresco, Liferay, etc. application installers that include Tomcat, MySQL, etc. at BitNami

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Daniel Lopez
  • 3,297
  • 2
  • 30
  • 29
0

A better way is to use IzPack, it is better than others because, it is only needed to be packaged once and can be used on any Operating System with same compiled jar.

I personally used it for packaging tomcat, mysql and some other prerequisites for my web application.

I used Launch4J for creating executable(.exe) from the IzPack generated jar file.

Alok
  • 361
  • 3
  • 4