使用InstallAnywhere工具打包Java_Web程序

 

一、准备工作

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都放在某个盘的同一个文件夹中;

二、编写两个批处理文件,分别为“注册服务.bat”、“启动.bat”、“卸载前必点.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就是完成的安装文件包。

posted @ 2016-11-29 15:27  写代码吧  阅读(1094)  评论(0编辑  收藏  举报