mysql tomocat vs2005_C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装
要求:
JDK、Mysql、Tomcat三者制作成一个安装包,
不能单独安装,安装过程不显示三者的界面,
安装完成要配置好JDK环境、Mysql服务、Tomcat 服务
目的:
解决客户在安装软件的复杂配置和繁琐
便于管理软件版本
便于系统集成
分析:
由于不能使用软件的原始安装版本,故只能将JDK的安装目录拷贝出来,放在D盘的SoftSource文件夹,由于要管理三者,将这三个放进一个文件夹里面
Mysql、Tomcat只能用解压版,要让软件运行起来,要做的事情如下:
配置JDK环境变量
这一步很重要,否则后面的Tomcat将不能正确运行,
2、安装Mysql服务,我用的是MySQL Server 5.5社区版、解压目录下面有my.ini文件,或者先将mysql安装,然后拷贝安装目录文件,目录结构不能变,安装方法是 用命令行将目录转到mysql的bin目录下,mysqld --install MySQL5 --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my.ini" 注意=后面就是你的mysql安装目录下的ini文件路径(可先行在cmd下测试安装,若可以,删除服务的只要将前面的安装语句里面的install改成uninstall)
难点在my.ini文件里面的datadir="D:/ProgramData/MySQL/MySQL Server 5.5/Data/"(数据安装目录)
basedir="D:/Program Files/MySQL/MySQL Server 5.5/" (软件安装目录)
需要与你的实际目录对应,否则会失败,另外要根据选择不同路径,该路径要可以跟着改变
3、安装Tomcat服务是要执行bin目录下面的service.bat文件用法命令行将目录的转到你的Tomcat 下的bin目录安装语句是
service.bat install 卸载 为service.bat uninstall 主要事项(bat文件必须要在当前目录执行,就是命令行的路径必须要转到bat文件的目录,另外需要JAVA_HOME环境变量,还有CATALINA_HOME环境变量(就是要将Tomcat安装目录加到环境变量))
思路清晰了,接着就是代码实现了,(先实现JDK和Mysql )
vs2008 新建 C#类库项目,添加组件Installer1.cs(安装组件)命名为MyInstallerClassDll
重写安装方法(安装前、安装、安装后)附上代码:
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Configuration.Install;
usingSystem.Windows.Forms;
usingSystem.IO;
usingSystem.Text;
usingSystem.Diagnostics;
namespaceCustomAction{
[RunInstaller(true)]
public partial classMyInstallerClassDll: Installer{
publicMyInstallerClassDll()
{
InitializeComponent();
}
protected override voidOnBeforeInstall(IDictionarysavedState)
{
stringserver= this.Context.Parameters["server"];
stringuser= this.Context.Parameters["user"];
base.OnBeforeInstall(savedState);
}
public override voidInstall(IDictionarystateSaver)
{
stringinstallPath= this.Context.Parameters["targetdir"];
stringserver= this.Context.Parameters["server"];
stringuser= this.Context.Parameters["user"];
//Mysql的配置文件IniFileini= newIniFile(installPath+ @"MySQL\MySQL Server 5.5\my.ini");
//mysql安装路径ini.Write("mysqld", "basedir", installPath+ @"MySQL\MySQL Server 5.5\");
//Mysql数据文件夹ini.Write("mysqld", "datadir", installPath+ @"MySQL\MySQL Server 5.5\Data\");
base.Install(stateSaver);
}
protected override voidOnAfterInstall(IDictionarysavedState)
{
stringinstallPath= this.Context.Parameters["targetdir"];
stringmysqlpath= installPath+ @"MySQL\MySQL Server 5.5\bin";
stringjrePath= installPath+ @"Java\jre6\bin";
stringiniPath= installPath+ @"MySQL\MySQL Server 5.5\my.ini";
stringtomcatPath= installPath+ @"Tomcat\Tomcat6\bin";
InstallMysql(mysqlpath, iniPath,true);
//设置Mysql环境变量SysEnvironment.SetPath(mysqlpath);
//设置JRE环境变量SysEnvironment.SetPath(jrePath);
//设置Tomcat环境变量SysEnvironment.SetPath(tomcatPath);
base.OnAfterInstall(savedState);
}
///
///安装与卸载Mysql服务///
///
///
/// 为true时安装,否则为卸载private static voidInstallMysql(stringmysqlpath, stringiniPath, boolisInstall)
{
//安装Mysql服务Processprocess= newProcess();
process.StartInfo.FileName= "cmd.exe";
process.StartInfo.UseShellExecute= false;
process.StartInfo.RedirectStandardInput= true;
process.StartInfo.RedirectStandardOutput= true;
process.StartInfo.RedirectStandardError= true;
process.StartInfo.CreateNoWindow= true;
process.Start();
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("cd "+ mysqlpath);
process.StandardInput.WriteLine(mysqlpath.Substring(2) + " cd");
//mysqld --install MySQLXY --defaults-file="D:\Program Files\MySQL\MySQL Server 5.5\my.ini"if(isInstall)
{
process.StandardInput.WriteLine("mysqld --install MySQL --defaults-file="+ '"'+ iniPath+ '"');
process.StandardInput.WriteLine("net start mysql");
}
else{
process.StandardInput.WriteLine("net stop mysql");
//mysqld --install MySQLXY --defaults-file="D:\Program Files\MySQL\MySQL Server 5.5\my.ini"process.StandardInput.WriteLine("mysqld --remove MySQL --defaults-file="+ '"'+ iniPath+ '"');
}
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("");
process.StandardInput.WriteLine("exit");
//Writefile(installPath,process.StandardOutput.ReadToEnd().ToString());process.Close();
}
public override voidUninstall(IDictionarysavedState)
{
stringinstallPath= this.Context.Parameters["targetdir"];
stringmysqlpath= installPath+ @"MySQL\MySQL Server 5.5\bin";
stringiniPath= installPath+ @"MySQL\MySQL Server 5.5\my.ini";
InstallMysql(mysqlpath, iniPath, true);
base.Uninstall(savedState);
}
///
///写日志///
///
/// public voidWritefile(stringpath, stringmsg)
{
stringfile= path+ @"日志.txt";
if(File.Exists(file))
File.Delete(file);
using(StreamWritersw= newStreamWriter(file, true))
{
sw.WriteLine(msg);
}
}
}
}
下面是SysEnvironment 类的代码,读取设置注册表的信息 代码已经封装好了,就不介绍了
(环境变量的注册表位置为HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001 / Session Manager/Environment)
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingMicrosoft.Win32;
namespaceCustomAction{
classSysEnvironment{
///
///获取系统环境变量///
///
/// public static stringGetSysEnvironmentByName(stringname)
{
stringresult= string.Empty;
try{
result= OpenSysEnvironment().GetValue(name).ToString();//读取}
catch(Exception)
{
return string.Empty;
}
returnresult;
}
///
///打开系统环境变量注册表///
/// RegistryKeyprivate staticRegistryKeyOpenSysEnvironment()
{
RegistryKeyregLocalMachine= Registry.LocalMachine;
RegistryKeyregSYSTEM= regLocalMachine.OpenSubKey("SYSTEM", true);//打开HKEY_LOCAL_MACHINE下的SYSTEMRegistryKeyregControlSet001= regSYSTEM.OpenSubKey("ControlSet001", true);//打开ControlSet001RegistryKeyregControl= regControlSet001.OpenSubKey("Control", true);//打开ControlRegistryKeyregManager= regControl.OpenSubKey("Session Manager", true);//打开ControlRegistryKeyregEnvironment= regManager.OpenSubKey("Environment", true);
returnregEnvironment;
}
///
///设置系统环境变量///
/// 变量名
/// 值public static voidSetSysEnvironment(stringname, stringstrValue)
{
OpenSysEnvironment().SetValue(name, strValue);
}
///
///检测系统环境变量是否存在///
///
/// public boolCheckSysEnvironmentExist(stringname)
{
if(!string.IsNullOrEmpty(GetSysEnvironmentByName(name)))
return true;
else
return false;
}
///
///添加到PATH环境变量(会检测路径是否存在,存在就不重复)///
/// public static voidSetPath(stringstrHome)
{
stringpathlist= GetSysEnvironmentByName("PATH");
string[] list= pathlist.Split(';');
boolisPathExist= false;
foreach(stringiteminlist)
{
if(item== strHome)
isPathExist= true;
}
if(!isPathExist)
{
SetSysEnvironment("PATH", pathlist+strHome+ ";");
}
}
}
}
好了,接下来创建Ini文件操作类,调用了系统api,已经封装好了,可以直接用了
usingSystem;
usingSystem.IO;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Runtime.InteropServices;
namespaceCustomAction{
public classIniFile{
private stringm_iniFileFullPath;
///
///ini文件路径///
/// publicIniFile(stringiniFilePath)
{
m_iniFileFullPath= iniFilePath;
}
///
///写入信息///
///
///
/// public voidWrite(stringiniSection, stringiniKey, stringiniValue)
{
WritePrivateProfileString(iniSection, iniKey, iniValue, this.m_iniFileFullPath);
}
///
///读取信息///
///
///
/// public stringRead(stringiniSection, stringiniKey)
{
StringBuilderresultValue= newStringBuilder(255);
inti= GetPrivateProfileString(iniSection, iniKey, "", resultValue,
255, this.m_iniFileFullPath);
returnresultValue.ToString();
}
///
///写入信息///
///
///
///
/// public voidWrite(stringiniSection, stringiniKey, stringiniValue, stringiniPath)
{
WritePrivateProfileString(iniSection, iniKey, iniValue, iniPath);
}
///
///读取信息///
///
///
///
/// public static stringRead(stringiniSection, stringiniKey, stringiniPath)
{
StringBuilderresultValue= newStringBuilder(255);
inti= GetPrivateProfileString(iniSection, iniKey, "", resultValue,
255, iniPath);
returnresultValue.ToString();
}
[DllImport("kernel32")]
private static extern longWritePrivateProfileString(stringsection,
stringkey, stringval, stringfilePath);
[DllImport("kernel32")]
private static extern intGetPrivateProfileString(stringsection,
stringkey, stringdef, StringBuilderretVal,
intsize, stringfilePath);
}
}
现在基本代码已经写好了,右键解决方案,添加安装部署项目,右键项目文件视图,新建文件夹Mysql、Java、Tomcat,将你的拷贝的Mysql贴进Mysql项目里面
接下来,右键应用程序文件夹添加主输出
然后右键项目,自定义操作视图,添加安装和卸载的操作(选中主输出)
好了,现在可以测试下了Mysql,未完待续。。。。。。。
下次接着写Tomcat
mysql tomocat vs2005_C# 制作Java +Mysql+Tomcat 环境安装程序,一键式安装相关推荐
- Eclipse 3.5 Classic+Tomcat 6.0+MySql 5.5搭建java web开发环境
Eclipse 3.5 Classic+Tomcat 6.0+MySql 5.5搭建java web开发环境 对于初学者来说,如果没有接触过java web开发的话,搭建开发环境将是一个门槛.以前一直 ...
- mysql 源码设计,java+mysql大学网络社区平台设计+源代码
摘要如今,信息管理与信息系统的网络平台上,更多的都是一些静态信息的介绍,缺乏老师与老师之间, 老师与同学之间信息的交流的功能. 因此, 需要建立一个从 Web 1.0转换到 Web 2.0 的, 能够 ...
- 如何配置Java和tomcat环境变量
一,Java环境配置 如果Java配置环境是在path中那么请将配置环境重新配置以下,如果是的话直接看下一步; (1)新建->变量名"JAVA_HOME",变量值" ...
- mysql 5.1.73路径_centos7.2 环境下 mysql-5.1.73 安装配置
安装mysql,安装前准备 如果mysql用户不存在,那么添加mysql用户 groupadd mysql useradd -g mysql mysql mysql编译安装 tar -zxvf mys ...
- weblogic测试环境安装部署--傻瓜式安装教程
测试环境weblogic部署手册 1.weblogic需要有jdk环境 1.1 通过xftp工具把jdk1.8的软件包传入到服务器的/usr/local中并解压 cd /usr/local tar - ...
- docker环境下docker-compose一键式搭建skywalking链路追踪服务
前言 本节内容我们使用docker-compose一键式搭建一套skywalking链路追踪服务,实现docker环境下的微服务链路追踪监控,在开始本节内容之前,我们需要提前安装好docker和doc ...
- jsp mysql留言板制作_Jsp+mysql 制作留言板
最近大致了解了下什么是JSP,然后制作了一個小的留言板,這里寫一點制作留言板的過程,希望能給大家幫助! 一.准備工作(安裝各種所需要用到的軟件) 2.tomcat 下載地址 3.mysql ...
- docker 发布tomcat项目_Docker部署java项目[tomcat环境]
公司的一个java项目,然后这是组长给的一个任务,部署到docker中. 部署更不用说啦,肯定要写Dockerfile,不多想,先下载我需要的环境包. 1. JDK [JDK下载地址](Java SE ...
- Java 配置Tomcat环境变量并使用(在windows中)
目录 1. 下载Tomcat 2. 配置环境变量 3. 测试访问 4. 修改配置文件 前言 在安装Tomcat之前需要先装好 Java 环境,不然Tomcat是运行不起来的 JDK8 下载地址:htt ...
最新文章
- MySQL数据库左连接查询left join ... on
- javascript + css 利用div的scroll属性让TAB动感十足
- 【原创】gooogleman亲自参与设计的三星Cortex A8 S5pv210 之Sate210核心板硬件用户手册(作者:gooogleman)...
- CG CTF PWN When did you born?
- C#WebBrowser控件使用教程与技巧收集
- Nginx教程-location配置
- labelme标注文件转coco json,coco json转yolo txt格式,coco json转xml, labelme标注文件转分割,boxes转labelme json
- 消息称苹果斥资2亿美元收购Xnor.ai;华为2000万英镑投资,加速发展HMS手机生态系统;国产SSD将迎来爆发……...
- oracle数据库同步异步优劣点,ORACLE数据库异步IO介绍
- 前端必须懂的计算机网络知识—(XSS、CSRF和HTTPS)
- html5学习笔记(section)
- Rethinking the smaller-norm-less-infromative assumption in channel pruning of convolution layers
- 荣耀V20是起点,一波炫酷荣耀潮配又来啦!
- Groundhog and 2-Power Representation
- Unity TileMap 2D 工具基础教程
- 设计一个权限系统-RBAC
- linux键盘模拟程序,linux下模拟键盘的几种方法
- stripe国际支付(对接支付宝、微信)
- js输出当前星期几--switch case
- WebDav的几种应用方法
热门文章
- Fast_Human_Pose_Estimation_Pytorch
- Invalid character escape '\o'.
- np.concatenate
- libstdc++.so.6: version `GLIBCXX_3.4.21' not found
- c++版 mulSpectrums
- 海思移植opencv+车辆检测
- Linux下编译cscope,linux环境下cscope使用
- python在windows的开发环境_Python合集之Python开发环境在Windows系统里面搭建
- java库加载,Java:使用依赖项加载共享库
- java实现链接数据库_Java 链接数据库