有没有一种方法可以创建包含整个 Java EE Web 应用程序的安装程序,并且最终用户只需执行一个安装程序而无需安装整个生产环境?
我的目的是让他们省去JDK + Tomcat的安装,如果你有更好的解决方案,请提供。
最佳答案
对于 Windows 环境,您可以创建安装程序,就像您可以通过为 linux 环境创建 shell 脚本来准备一样。
1、打包s/w的二进制发行版(例如postgresql、jetty、jre等...)
2、将你的war文件放到jetty webapps中
3、在postgres中创建data文件夹
4、使用批处理文件设置各种环境变量和初始化。就我而言,我创建了以下“install.bat”文件。
REM set jdk environment
PATH=%~dp0Java\jre6\bin;%~dp0Java\jre6\lib;%~dp0pgsql\bin;%PATH%
setx PATH "%PATH%"
REM set postgres environment
SETX PGDATA "%~dp0pgsql\data"
SETX PGDATABASE postgres
SETX PGUSER postgres
SETX PGPORT 5432
SETX PGLOCALEDIR "%~dp0pgsql\share\locale"
REM initdb initialize the postgresql initialization properties
"%~dp0pgsql\bin\initdb" -D "%~dp0pgsql\data" -U postgres -A trust
REM put the temp.vbs script into startup
cscript //NoLogo //B "%~dp0start_startup_shortcut.vbs"
cscript //NoLogo //B "%~dp0start_desktop_shortcut.vbs"
cscript //NoLogo //B "%~dp0app_shortcut.vbs"
REM start the database service
"%~dp0pgsql\bin\pg_ctl" -D "%~dp0pgsql\data" start
timeout /T 10
"%~dp0pgsql\bin\createdb.exe" -U postgres dbName
"%~dp0pgsql\bin\psql.exe" -U postgres -d dbName -f "%~dp0backup.sql"
REM java -DSTART="%~dp0jetty8\start.ini" -jar "%~dp0jetty8\start.jar"
REM start the jetty server
java -Djetty.home="%~dp0jetty8" -jar "%~dp0jetty8\start.jar" > pb_log.txt
pause
5、创建批处理文件启动服务。例如“start.bat”
REM start the database service
"%~dp0pgsql\bin\pg_ctl" -D "%~dp0pgsql\data" start
java -Djetty.home="%~dp0jetty8" -jar "%~dp0jetty8\start.jar"
6、您可以按如下方式创建应用程序快捷方式。例如“app_shortcut.vbs”
Dim FileName
FileName = "projectName"
Set wsShell= CreateObject("WScript.Shell")
Set wshSysEnv = wsShell.Environment("PROCESS")
sMyHomePath = wshSysEnv("HOMEPATH")
Set shortcut =
wsShell.CreateShortcut(CreateObject("WScript.Shell").SpecialFolders("Desktop")& + "\" +
FileName + ".lnk")
shortcut.Description = "Start projectName"
currentDirectory = left(WScript.ScriptFullName,
(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
shortcut.TargetPath = currentDirectory + "projectName.bat"
shortcut.Arguments = "/Arguments:Shortcut"
shortcut.Save
7、启动服务桌面快捷方式如下:
Dim FileName
FileName = "Start projectName Server"
Set wsShell= CreateObject("WScript.Shell")
Set wshSysEnv = wsShell.Environment("PROCESS")
sMyHomePath = wshSysEnv("HOMEPATH")
Set shortcut =
wsShell.CreateShortcut(CreateObject("WScript.Shell").SpecialFolders("Desktop")& + "\" +
FileName + ".lnk")
shortcut.Description = "Start projectName"
currentDirectory = left(WScript.ScriptFullName,
(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
shortcut.TargetPath = currentDirectory + "start.bat"
shortcut.Arguments = "/Arguments:Shortcut"
shortcut.Save
8、运行应用批处理文件
@echo off
netstat -o -n -a | findstr 0.0:9095
if %ERRORLEVEL% equ 0 (start http://localhost:9095) ELSE (echo "Please Start the Server"
pause)
关于jakarta-ee - 如何在单个安装程序中为 Java EE Web 应用程序创建安装程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10456741/