如何创建包含 Tomcat 和 MySQL 的 Java webapp 安装程序 (.exe)?”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/856772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create Java webapp installer (.exe) that includes Tomcat and MySQL?"
提问by Wilson
How to create a installer using Java that combine tomcat, mysql and war file and come out a final exe?
如何使用 Java 创建一个结合 tomcat、mysql 和 war 文件的安装程序并生成最终的 exe?
采纳答案by Gerco Dries
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. Customize some configuration files and run the MySQL installer in silent mode. All of which is perfectly possible with InnoSetup.
在您的情况下,您可能希望将 Tomcat 文件放在某个地方,包括 webapp。自定义一些配置文件并以静默模式运行 MySQL 安装程序。所有这一切都可以通过 InnoSetup 实现。
If you need more flexibility, you can look at NSIS, another very simple but very powerful installer app.
如果您需要更多的灵活性,您可以查看NSIS,这是另一个非常简单但非常强大的安装程序应用程序。
回答by Mork0075
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).
我建议您为此使用 Java,一个 installer.jar。由于您无论如何都想运行tomcat,因此无需放入exe文件。我们做了类似的事情,在 Ant API(Ant 以编程方式使用)的帮助下编写了一个 jar 安装程序。
回答by Jonik
The possible options have been largely covered in several questions already, especially:
可能的选项已经在几个问题中得到了广泛的介绍,尤其是:
- What's the best way to distribute Java applications?
- What is the best installation tool for java?
- What are good InstallAnywhere replacements for installing a Java EE application?
...and other questions tagged java + installer
...和其他标记为 java + 安装程序的问题
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.
尽管不可否认,这些问题中提到的某些选项无法生成自给自足的 .exe 安装程序。如果商业工具适合你,我个人可以推荐install4j(费用 $);除其他外,它可以创建 .exe 安装程序(有关我使用它的经验的详细信息)。或者,有关从 Java 程序生成 Windows 可执行文件的更简单的免费工具,请参阅Launch4j。
Updateof 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. At the end, users only need to start the tomcat and mysql service. Go to browser can access the web application.
是的,exe 安装程序需要一次性安装 tomcat、mysql、web 应用程序和 db 脚本。最后用户只需要启动tomcat和mysql服务即可。转到浏览器可以访问 Web 应用程序。
With install4j,
使用 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 :-)
- 你可以捆绑 Tomcat、MySQL 和你的 webapp 就好了
- 您也可以从安装程序自动启动服务(或按照您的建议将其留给用户)
- 如果需要,安装程序甚至可以直接启动浏览器并将其指向您的 web 应用程序 :-)
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.
我刚刚用 install4j 做了一个类似的事情(捆绑应用程序服务器、webapp、运行数据库脚本和许多其他事情;但是没有捆绑数据库),所以我相对确定它可以完成。我不知道您是否可以(轻松)使用 Launch4j 等免费工具执行此操作。
回答by Daniel Lopez
You can use BitRock InstallBuilderfor it (costs $). For examples of such programs, checkout Alfresco, Liferay, etc. application installers that include Tomcat, MySQL, etc. at BitNami
您可以使用BitRock InstallBuilder(费用为 $)。有关此类程序的示例,请查看BitNami 的Alfresco、Liferay 等应用程序安装程序,其中包括 Tomcat、MySQL 等
回答by Amir Jamak
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.
这是我对这个问题的简约解决方案。我已经下载了没有安装程序的 tomcat 和 MySQL 安装,所以我只是解压缩它们,我试过它们工作正常。此时你将把war文件安装到tomcat,并将相关的schema安装到mysql。因此,当您复制文件夹时,所有内容都会被复制。你可以测试它是如何工作的。也许你可以对它们进行一些调整,但对我来说,它们开箱即用的效果很好,因为我的应用程序并不那么苛刻。除此之外,我已经下载了 32 位和 64 位版本的程序,因此它们都可以安装。我使用 Inno setup 打包安装程序。基本上它只通过选择 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
为了现在运行您的应用程序,您只需要启动/停止注册的服务。启动文件
NET START MyApp_MySQL
NET START MyApp_Tomcat
START "" "http://localhost:8080/myapp/"
stop.bat
停止.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.
- 也许您也可以包含 JRE 安装,因为某些组件可能没有它。
- 另外,如果有人知道如何检查 tomcat 和 mysql 端口是否已经被占用,以及如何在 conf 文件中更改它们,请告诉我们。
- 此外,如果您可以检查 IP 地址并键入它而不是 localhost,那就太好了。
Regards
问候
Amir
阿米尔
回答by Alok
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 Launch4Jfor creating executable(.exe) from the IzPack generated jar file.
我使用Launch4J从 IzPack 生成的 jar 文件创建可执行文件(.exe)。