原由

在搭建Java Web学习环境时将Tomcat安装到了C盘,在Win7下因管理权限导致修改文档很不方便,便想卸载后重装到D盘。

没想到折腾了半天...虽然很简单,姑且整理出来,做个参考也好。

卸载

尝试了两种卸载方式

1.卸载服务

命令行下进入 X:\Program Files\Apache Software Foundation\Tomcat 9.0\bin

运行 service.bat remove tomcat9

注:

remove --卸载服务

tomcat9 --被卸载的服务名(service.bat设置了默认的服务名,tomcat4、tomcat5...即tomcat+版本号)

报错:

the JAVA_HOME environment variable is not defined correctly this environment variable is needed to run this program NB:JAVA_HOME should point to a JDK not a JRE

解决办法:

提示JAVA_HOME环境变量设置不正确。

但是在 计算机->属性->高级->环境变量->系统变量->JAVA_HOME 检查无误,确为Java的的安装路径。

困惑中注意到最后一句提示:JAVA_HOME应该指向JDK而非JRE

问题就在这。

JDK:提供Java开发环境和运行环境,开发者使用的SDK(Software Development Kit)

JRE:提供Java运行环境,一般为用户使用。

经查看,先前安装的是jre版。好吧,改装jdk版即可。

二者的安装包对比:

官网下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

安装JDK版后重新设置JAVA_HOME,再次运行卸载服务命令,成功。

2.卸载tomcat程序

双击运行安装路径下的 Uninstall.exe。

报错:

No service name specified to uninstall. This will be provided automatically if you uninstakk via add/romove programs oor the shortcut on tthe Start menu. Alternatively,call the installer from the command line with -ServiceName"".

解决办法:

在命令行中运行 Uninstall.exe,根据提示添加参数:

Uninstall.exe -ServiceName=""

卸载完成。