简体   繁体   中英

How to create Java webapp installer (.exe) that includes Tomcat and MySQL?"

如何使用结合了tomcat,mysql和war文件的Java创建一个安装程序并出来一个最终的exe?

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.

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.

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

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).

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM