一、准備工作
1、 下載InstallAnywhere,並安裝;
2、 下載解壓版jdk1.7(示例為jdk1.7.0_75);
3、 下載解壓版tomcat7.0以上版本(示例為apache-tomcat-7.0.72);
4、 下載解壓版MySQL5.0以上的版本(示例為mysql-5.6.26);
5、 將web項目放在tomcat的webapps中,將該項目的數據庫也同步到解壓版的MySQL中,然後將jdk、tomcat、MySQL都放在某個盤的同一個文件夾中;
二、編寫兩個批處理文件,分別為“install.bat”、“uninstall.bat”
注冊服務.bat裡的內容
echo "注冊mysql服務"
cd mysql5.0\bin
mysqld -install mysql-iams
啟動.bat裡的內容
cd mysql5.0\bin
echo "啟動mysql服務"
net start mysql-iams
cd..
cd..
cd apache-tomcat-7.0.72\bin
call startup.bat
卸載前必點.bat裡的內容:
cd mysql5.0\bin
net stop mysql-iams
mysqld remove mysql-iams
cd..
cd..
cd apache-tomcat-7.0.72\bin
call shutdown.bat
三、建立project
打開InstallAnywhere,建立Typical Project Template,然後選擇Advanced Designer,設置Title, Name等
四 、本地化語言
菜單Project>Locales>,選擇需要的本地化語言。
五、設置環境變量
菜單Install>,按鈕Add Action...>Set System Environment Variable>Add>,設JAVA_HOME和CATALINA_HOME,CATALINA_DIR,PATH 四個系統環境變量。其中$USER_INSTALL_DIR$表示用戶選擇的安裝路徑。
JAVA_HOME :$USER_INSTALL_DIR$\ jdk1.7.0_75
CATALINA_HOME:$USER_INSTALL_DIR$\ apache-tomcat-7.0.72
CATALINA_DIR:$USER_INSTALL_DIR$\ apache-tomcat-7.0.72\bin
PATH:$USER_INSTALL_DIR$\ jdk1.7.0_75
\bin;$USER_INSTALL_DIR$\mysql5.0\bin;$USER_INSTALL_DIR$\apache-tomcat-7.0.72\bin;c:\windows\system32
然後把jdk,tomcat,mysql 通過按鈕Add Files...添加進來放在 User Install Folder直接目錄下,如圖所示:
六、注冊服務
1、菜單Post-Install>,按鈕Add Action...>Execute Command>Add>,在安裝完成後執行install.bat,注冊Tomcat和MySQL服務。其中Command Line:cmd /c $USER_INSTALL_DIR$\install.bat $USER_INSTALL_DIR$。並且,選中Options中的3個選項。將該Execute Command移動到Panel: Install Complete前面。
2、然後添加按鈕Add Action...>Motify Text File-Single File>Add>,然後在Installed file選中mysql安裝目錄下的my.in(如果沒有這個文件,請先創建這樣一個文件,內容為空),其中Additional Text選中第一個prepend,在文本框中輸入:
# For advice on how to change settings please see
#http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#設置數據庫引擎為INNODB
default-storage-engine=INNODB
# 設置mysql服務器編碼
character_set_server=utf8
# 設置mysql服務器字符集
collation-server=utf8_general_ci
[client]
# 設置mysql客戶端默認字符集
default-character-set = GBK
[WinMySQLAdmin]
Server = $USER_INSTALL_DIR$\mysql5.0\bin\mysqladmin.exe
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# 設置mysql的安裝目錄,如果目錄中帶空格則必須加引號
basedir=$USER_INSTALL_DIR$\mysql5.0
# 設置mysql數據庫的數據的存放目錄,文件夾名必須是data
datadir = $USER_INSTALL_DIR$\mysql5.0\data
# 允許最大連接數
max_connections=200
#設置3306端口
# port = 3306
# server_id = 1
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
將該Motify Text File-Single File移動到Panel: Install Complete後面。
3、然後添加按鈕Add Action...>Excute Script/Batch file>Add>,其中Commnet:啟動mysql(就是啟動mysql的,可以是寫任意東西,只有自己懂就行)
Script中輸入:net start mysql
將該Excute Script/Batch file移動到Motify Text File-Single File後面。
七、讓安裝完成後啟動浏覽器,自動打開項目
菜單Post-Install>,按鈕Add Action...>Launch Default Browser>Add>OtherUrl中填入項地址 localhost:8080/ProjectName,將該Launch Default Browser移動到Panel: Install Complete後面。
八、反安裝
菜單Pre-Uninstall>,按鈕Add Action>Execute Command>Add>。
Command Line: cmd /c $USER_INSTALL_DIR$\uninstall.bat $USER_INSTALL_DIR$
將該Execute Command移動到第一個。選中Options中的3個選項。
九、打包
菜單Build>,按鈕Build Project>,等待InstallAnywhere打包完成。
完成以後,按鈕Open in Explorer>,文件夾Web_Installers>InstData>Windows>VM>,install.exe就是完成的安裝文件包。