1、自Javaweb系统打包成exe安装文件Java web系统打包成exe安装文件一、工具准备1、NSIS打包工具: 下载并安装;2、NSIS安装脚本的编辑器HM NIS Editor:.net下载并安装二、运行环境准备JDK1、新建打包用的文件夹(本人是在D盘根目录下创建的webExe,即D:webExe);2、JDK本人用的是jdk-6u18,将安装好的JDK目录直接拷贝到目录webExe下就行(绿色版本的也可以)。三、应用程序准备Tomcat及web应用系统1、免安装版本的tomcat,本人用的是apache-tomcat-6.0.35,将其放到目录webExe下,并将Web应用系统发布进
2、webapps中。四、数据库准备mysql及数据1、下载一个免安装版本的mysql(本人操作系统是WIN 7 32位,下载的是mysql-noinstall-v5.1.55.zip),解压缩到D盘;2、将主目录名mysql-5.1.55-win32修改为简单的mysql5(不修改也行,建议修改简单);3、找到文件my-small.ini改名为my.ini(也可以是将my-huge.ini、my-large.ini、my-medium.ini中任意一个改名为my.ini);4、将my.ini打开进行配置:# The following options will be passed to all
3、MySQL clientsclient#password = your_passwordport = 3306socket = MySQLdefault-character-set = utf8 -客户端编码# Here follows entries for some specific programs# The MySQL servermysqldport = 3306socket = MySQLdefault-character-set = utf8 -服务器端basedir=D:/mysql5 -路径datadir=D:/mysql5/data -数据库路径default-storag
4、e-engine = MyISAM -默认数据库引擎为MyISAM5、在本地启动服务,导入数据库及数据(如果本机已经安装了mysql,记得关掉当前的服务)运行cmd.exe进入DOS窗口,进到D:mysql5bin目录注册服务: mysqld -install mysql5 -defaults-file=d:mysql5my.ini可能会出现Install/Remove of the Service Denied! 错误,这时要关闭DOS窗口,以管理员的身份运行cmd.exe程序。启动服务:net start mysql5使用命令或mysql第三方客户端,创建数据库并导入数据停止服务:net
5、stop mysql5参考图片6、停止服务后,将mysql5整个目录剪切到目录webExe下五、打包脚本准备1、当前目录情况如下图:2、脚本文件AddPath.nsh(复制到编辑器HM NIS Edit中保存)!ifndef _AddToPath_nsh!define _AddToPath_nsh !verbose 3!include WinMessages.NSH!verbose 4 !ifndef WriteEnvStr_RegKey !ifdef ALL_USERS !define WriteEnvStr_RegKey HKLM SYSTEMCurrentControlSetContro
6、lSession ManagerEnvironment !else !define WriteEnvStr_RegKey HKCU Environment !endif!endif ; AddToPath - Adds the given dir to the search path.; Input - head of the stack; Note - Win9x systems requires reboot Function AddToPath Exch $0 Push $1 Push $2 Push $3 # dont add if the path doesnt exist If $
7、0*.* AddToPath_done ReadEnvStr $1 PATH Push $1; Push $0; Call StrStr Pop $2 StrCmp $2 AddToPath_done Push $1; Push $0; Call StrStr Pop $2 StrCmp $2 AddToPath_done GetFullPathName /SHORT $3 $0 Push $1; Push $3; Call StrStr Pop $2 StrCmp $2 AddToPath_done Push $1; Push $3; Call StrStr Pop $2 StrCmp $2
8、 AddToPath_done Call IsNT Pop $1 StrCmp $1 1 AddToPath_NT ; Not on NT StrCpy $1 $WINDIR 2 $1 $1autoexec.bat a $1 -1 END $1 $2 IntCmp $2 26 0 +2 +2 # DOS EOF $1 -1 END # write over EOF $1 $r$nSET PATH=%PATH%;$3$r$n $1 SetRebootFlag true Goto AddToPath_done AddToPath_NT: ReadRegStr $1 $WriteEnvStr_Reg
9、Key PATH StrCmp $1 AddToPath_NTdoIt Push $1 Call Trim Pop $1 StrCpy $0 $1;$0 AddToPath_NTdoIt: WriteRegExpandStr $WriteEnvStr_RegKey PATH $0 SendMessage $HWND_BROADCAST $WM_WININICHANGE 0 STR:Environment /TIMEOUT=5000 AddToPath_done: Pop $3 Pop $2 Pop $1 Pop $0FunctionEnd ; RemoveFromPath - Remove a
10、 given dir from the path; Input: head of the stack Function un.RemoveFromPath Exch $0 Push $1 Push $2 Push $3 Push $4 Push $5 Push $6 IntFmt $6 %c 26 # DOS EOF Call un.IsNT Pop $1 StrCmp $1 1 unRemoveFromPath_NT ; Not on NT StrCpy $1 $WINDIR 2 $1 $1autoexec.bat r GetTemp $4 $2 $4 w GetFullPathName /
11、SHORT $0 $0 StrCpy $0 SET PATH=%PATH%;$0 Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoop: $1 $3 StrCpy $5 $3 1 -1 # read last char StrCmp $5 $6 0 +2 # if DOS EOF StrCpy $3 $3 -1 # remove DOS EOF so we can compare StrCmp $3 $0$r$n unRemoveFromPath_dosLoopRemoveLine StrCmp $3 $0$n unRemoveFromP
12、ath_dosLoopRemoveLine StrCmp $3 $0 unRemoveFromPath_dosLoopRemoveLine StrCmp $3 unRemoveFromPath_dosLoopEnd $2 $3 Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoopRemoveLine: SetRebootFlag true Goto unRemoveFromPath_dosLoop unRemoveFromPath_dosLoopEnd: $2 $1 StrCpy $1 $WINDIR 2 Delete $1autoexe
13、c.bat CopyFiles /SILENT $4 $1autoexec.bat Delete $4 Goto unRemoveFromPath_done unRemoveFromPath_NT: ReadRegStr $1 $WriteEnvStr_RegKey PATH StrCpy $5 $1 1 -1 # copy last char StrCmp $5 ; +2 # if last char != ; StrCpy $1 $1; # append ; Push $1 Push $0; Call un.StrStr ; Find $0; in $1 Pop $2 ; pos of o
14、ur dir StrCmp $2 unRemoveFromPath_done ; else, it is in path # $0 - path to add # $1 - path var StrLen $3 $0; StrLen $4 $2 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove StrCpy $6 $2 $3 # $6 is now the part after the path to remove StrCpy $3 $5$6 StrCpy $5 $3 1 -1 # copy last char S
15、trCmp $5 ; 0 +2 # if last char = ; StrCpy $3 $3 -1 # remove last char WriteRegExpandStr $WriteEnvStr_RegKey PATH $3 SendMessage $HWND_BROADCAST $WM_WININICHANGE 0 STR:Environment /TIMEOUT=5000 unRemoveFromPath_done: Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0FunctionEnd ; AddToEnvVar - Adds the
16、 given value to the given environment var; Input - head of the stack $0 environement variable $1=value to add; Note - Win9x systems requires reboot Function AddToEnvVar Exch $1 ; $1 has environment variable value Exch Exch $0 ; $0 has environment variable name DetailPrint Adding $1 to $0 Push $2 Pus
17、h $3 Push $4 ReadEnvStr $2 $0 Push $2; Push $1; Call StrStr Pop $3 StrCmp $3 AddToEnvVar_done Push $2; Push $1; Call StrStr Pop $3 StrCmp $3 AddToEnvVar_done Call IsNT Pop $2 StrCmp $2 1 AddToEnvVar_NT ; Not on NT StrCpy $2 $WINDIR 2 $2 $2autoexec.bat a $2 -1 END $2 $3 IntCmp $3 26 0 +2 +2 # DOS EOF
18、 $2 -1 END # write over EOF $2 $r$nSET $0=%$0%;$4$r$n $2 SetRebootFlag true Goto AddToEnvVar_done AddToEnvVar_NT: ReadRegStr $2 $WriteEnvStr_RegKey $0 StrCpy $3 $2 1 -1 # copy last char StrCmp $3 ; 0 +2 # if last char = ; StrCpy $2 $2 -1 # remove last char StrCmp $2 AddToEnvVar_NTdoIt StrCpy $1 $2;$
19、1 AddToEnvVar_NTdoIt: WriteRegExpandStr $WriteEnvStr_RegKey $0 $1 SendMessage $HWND_BROADCAST $WM_WININICHANGE 0 STR:Environment /TIMEOUT=5000 AddToEnvVar_done: Pop $4 Pop $3 Pop $2 Pop $0 Pop $1 FunctionEnd ; RemoveFromEnvVar - Remove a given value from a environment var; Input: head of the stack F
20、unction un.RemoveFromEnvVar Exch $1 ; $1 has environment variable value Exch Exch $0 ; $0 has environment variable name DetailPrint Removing $1 from $0 Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 IntFmt $7 %c 26 # DOS EOF Call un.IsNT Pop $2 StrCmp $2 1 unRemoveFromEnvVar_NT ; Not on NT StrCpy $
21、2 $WINDIR 2 $2 $2autoexec.bat r GetTemp $5 $3 $5 w GetFullPathName /SHORT $1 $1 StrCpy $1 SET $0=%$0%;$1 Goto unRemoveFromEnvVar_dosLoop unRemoveFromEnvVar_dosLoop: $2 $4 StrCpy $6 $4 1 -1 # read last char StrCmp $6 $7 0 +2 # if DOS EOF StrCpy $4 $4 -1 # remove DOS EOF so we can compare StrCmp $4 $1
22、$r$n unRemoveFromEnvVar_dosLoopRemoveLine StrCmp $4 $1$n unRemoveFromEnvVar_dosLoopRemoveLine StrCmp $4 $1 unRemoveFromEnvVar_dosLoopRemoveLine StrCmp $4 unRemoveFromEnvVar_dosLoopEnd $3 $4 Goto unRemoveFromEnvVar_dosLoop unRemoveFromEnvVar_dosLoopRemoveLine: SetRebootFlag true Goto unRemoveFromEnvV
23、ar_dosLoop unRemoveFromEnvVar_dosLoopEnd: $3 $2 StrCpy $2 $WINDIR 2 Delete $2autoexec.bat CopyFiles /SILENT $5 $2autoexec.bat Delete $5 Goto unRemoveFromEnvVar_done unRemoveFromEnvVar_NT: ReadRegStr $2 $WriteEnvStr_RegKey $0 StrCpy $6 $2 1 -1 # copy last char StrCmp $6 ; +2 # if last char != ; StrCp
24、y $2 $2; # append ; Push $2 Push $1; Call un.StrStr ; Find $1; in $2 Pop $3 ; pos of our dir StrCmp $3 unRemoveFromEnvVar_done ; else, it is in path # $1 - path to add # $2 - path var StrLen $4 $1; StrLen $5 $3 StrCpy $6 $2 -$5 # $6 is now the part before the path to remove StrCpy $7 $3 $4 # $7 is n
25、ow the part after the path to remove StrCpy $4 $6$7 StrCpy $6 $4 1 -1 # copy last char StrCmp $6 ; 0 +2 # if last char = ; StrCpy $4 $4 -1 # remove last char WriteRegExpandStr $WriteEnvStr_RegKey $0 $4 ; delete reg value if null StrCmp $4 0 +2 # if null delete reg DeleteRegValue $WriteEnvStr_RegKey
26、$0 SendMessage $HWND_BROADCAST $WM_WININICHANGE 0 STR:Environment /TIMEOUT=5000 unRemoveFromEnvVar_done: Pop $7 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0FunctionEnd !ifndef IsNT_KiCHiK!define IsNT_KiCHiK # Utility Functions # ; IsNT; no input; output, top of the stack = 1 if NT or 0 if not; U
27、sage:; Call IsNT; Pop $R0; ($R0 at this point is 1 or 0) !macro IsNT unFunction $unIsNT Push $0 ReadRegStr $0 HKLM SOFTWAREMicrosoftWindows NTCurrentVersion CurrentVersion StrCmp $0 0 IsNT_yes ; we are not NT. Pop $0 Push 0 Return IsNT_yes: ; NT! Pop $0 Push 1FunctionEnd!macroend!insertmacro IsNT !i
28、nsertmacro IsNT un. !endif ; IsNT_KiCHiK ; StrStr; input, top of stack = string to search for; top of stack-1 = string to search in; output, top of stack (replaces with the portion of the string remaining); modifies no other variables.; Usage:; Push this is a long ass string; Push ass; Call StrStr; Pop $R0; ($R0 at this point is ass string) !macro StrStr unFunction $unStrStrExch $R1 ; st=haystack,old$R1, $R1=needle Exch ; st=old$R1,haystack Exch $R2 ; st=old$R1,old$R2, $R2=haystack Push $R3 Push $R4 Push $R5 StrLen $R3 $R1 StrCpy $R4 0 ; $R1=needle ; $R2
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1