简体   繁体   English

如何创建包含Tomcat和MySQL的Java webapp安装程序(.exe)?“

[英]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. 我个人使用了InnoSetup ,这非常简单,但在安装时仍然可以执行几乎任何任务。

In your case, you probably want to place the Tomcat files somewhere, webapp included. 在您的情况下,您可能希望将Tomcat文件放在某处,包括webapp。 Customize some configuration files and run the MySQL installer in silent mode. 自定义一些配置文件并以静默方式运行MySQL安装程序。 All of which is perfectly possible with InnoSetup. InnoSetup完全可以实现所有这些功能。

If you need more flexibility, you can look at NSIS , another very simple but very powerful installer app. 如果您需要更多灵活性,可以查看NSIS ,这是另一个非常简单但非常强大的安装程序应用程序。

The possible options have been largely covered in several questions already, especially: 可能的选项已经在很多问题中得到了很好的解决,特别是:

...and other questions tagged java + installer ...以及标记为java +安装程序的其他问题

Although admittedly some options mentioned in those questions cannot produce self-sufficient .exe installers. 虽然不可否认,这些问题中提到的一些选项无法生成自给自足的.exe安装程序。 If a commercial tool is ok for you, I can personally recommend install4j (costs $); 如果商业工具适合您,我个人推荐install4j (费用$); among other things, it can create .exe installers ( details about my experiences with it ). 除此之外,它还可以创建.exe安装程序( 有关我使用它的经验的详细信息 )。 Or, for a simpler, free tool for producing Windows executables out of Java programs, see Launch4j . 或者,对于使用Java程序生成Windows可执行文件的更简单,免费的工具,请参阅Launch4j

Update of my install4j recommendation, based on this comment by OP: 根据OP的评论更新我的install4j推荐:

Yes, the exe installer need to install the tomcat, mysql, web application, and db script all in once. 是的,exe安装程序需要一次性安装tomcat,mysql,web应用程序和db脚本。 At the end, users only need to start the tomcat and mysql service. 最后,用户只需要启动tomcat和mysql服务。 Go to browser can access the web application. 转到浏览器可以访问Web应用程序。

With install4j, 使用install4j,

  • you can bundle Tomcat, MySQL and your webapp just fine 你可以捆绑Tomcat,MySQL和你的webapp就好了
  • 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 :-) 如果需要,安装程序甚至可以直接启动浏览器并将其指向您的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. 我刚刚用install4j做了类似的事情(捆绑应用程序服务器,webapp,运行数据库脚本,以及许多其他东西;但是没有捆绑数据库),所以我相对肯定它可以完成。 I do not know if you can do this (easily) with the free tools such as Launch4j. 我不知道你是否可以使用诸如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. 我已经下载了没有安装程序的tomcat和MySQL安装,所以我只是解压缩它们,我试过它们工作正常。 At this moment you will install the war file to tomcat, and relevant schema to the mysql. 此时您将war文件安装到tomcat,并将相关模式安装到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. 除此之外,我已经下载了32位和64位版本的程序,因此它们都可以安装。 I used Inno setup to pack the installer up. 我使用Inno设置来打包安装程序。 Basically it only copies both folders by choosing 32 or 64 architecture, and installs both, tomcat and mysql, as windows service. 基本上它只通过选择32或64架构来复制这两个文件夹,并安装tomcat和mysql作为windows服务。

[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 的start.bat

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

stop.bat 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. 也许您也可以包含JRE安装,因为某些comp可能没有它。
  • 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. 此外,如果有人知道如何检查是否已经采取了tomcat和mysql端口,以及如何在conf文件中更改它们,请告诉我们。
  • Also if you can inspect the IP address and type it instead of localhost that would be great. 此外,如果你可以检查IP地址并键入它而不是localhost那将是伟大的。

Regards 问候

Amir 阿米尔

I would suggest, that you use Java for this, a installer.jar. 我建议你使用Java,即installer.jar。 As you would like to run tomcat anyway, theres no need to put in a exe file. 因为你想运行tomcat,所以不需要输入exe文件。 We've done something similar, programming an jar installer with the help of the Ant API (Ant used programmatically). 我们已经做了类似的事情,在Ant API的帮助下编写了jar安装程序(Ant以编程方式使用)。

You can use BitRock InstallBuilder for it (costs $). 你可以使用BitRock InstallBuilder (费用$)。 For examples of such programs, checkout Alfresco, Liferay, etc. application installers that include Tomcat, MySQL, etc. at BitNami 有关此类程序的示例,请在BitNami上查看包含Tomcat,MySQL等的Alfresco,Liferay等应用程序安装程序。

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. 更好的方法是使用IzPack ,它比其他更好,因为它只需要打包一次,并且可以在具有相同编译jar的任何操作系统上使用。

I personally used it for packaging tomcat, mysql and some other prerequisites for my web application. 我个人用它来打包我的web应用程序的tomcat,mysql和其他一些先决条件。

I used Launch4J for creating executable(.exe) from the IzPack generated jar file. 我使用Launch4J从IzPack生成的jar文件创建可执行文件(.exe)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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