[Details] Tomcat download, install, set up as a Windows service, start and pit encountered

As a back-end Java programmer (or preparing to become the back-end Java programmers), for Tomcat must be familiar with.

Although most of the time Tomcat is running on a Linux server.

But inevitably have to install Tomcat on a Windows computer from our daily local development and debugging.

This article will record operating under installation of Tomcat, and some of the pits encountered it.

The first step: Tomcat download

The first step of course is to get a Tomcat installation package of it!

Here is Tomcat7,8,9 three versions of the official download address.

  • Tomcat 9
  • Tomcat 8
  • Tomcat 7
    attention to try to go to the official website to download software to download oh (Tomcat, after all, not for money).

Here we have an example to explain to Tomcat8 (because this version I used, in order to be lazy!)

Click on the Tomcat 8 to enter Tomcat8 download page. The system is based on their 64-bit or 32, select the corresponding zip package. (Yes, Tomcat support mounted directly extract, is very convenient)
as shown below:
Tomcat8 download .png

After the download is good that we can extract up. For example, I extracted to the following directory:
image.png

Here, we have done the first step in it!

Step 2: Install

In fact, after downloading, we start up Tomcat distance needs to be done has been very small. Installation This step is mainly to set the environment variable. There are two environment variables need to set --JAVA_HOME and CATALINA_HOME.

JAVA_HOME is the Java installation directory. What, you say you have not installed JDK? Go download a. For example, I installed the JDK in the following location:
JDK installation location

Tomcat is mounted in the following positions:
Tomcat installation location

Then I set JAVA_HOME to D: \ Program Files \ Java \ jdk1.8.0_211.

CATALINA_HOME is set to D: \ Program Files \ apache-tomcat-8.5.50

Specifically as shown below:
Environment variable settings

As to set the system environment or user variables, in fact, can. User environment variables I set here.

This step is done for you, is not getting easier!

第三步:设置为Windows服务

其实作为上述两步就可以启动Tomcat了。但我们为了以后使用的方便,直接将Tomcat设置为Windows服务。

这里需要通过命令提示符窗口执行Tomcat bin目录下的service.bat。按常规做法我们需要通过cd命令一步步进入tomcat的bin目录,十分麻烦。

所以,这里有个小技巧:

我们打开Tomcat的安装目录,进入bin文件夹,按住shift再点击右键,这时菜单里就出现了“在此打开命令提示符”(win7)或“在此打开PowerShell窗口”。
In this open PowerShell.png
这样打开的“命令提示符”或“Powershell”窗口,默认的目录就是当前目录。

然后我们只需要执行以下命令:

service.bat install Tomcat8

就可以将Tomcat设置为Windows服务啦。这里的Tomcat8是我们指定的服务名,这个名字可以自己任意起,这里我习惯叫做Tomcat8。

注意如果是Win10系统,需要这么写:

.\service.bat install Tomcat8

我执行的情况如下:

可以看到最后一句Tes service 'Tomcat8' has been installed.说明我们安装成功啦!

同时输出的信息也可以看出我们之前设置的JAVA_HOME和CATALINA_HOME也起了作用。

第四步:启动

终于到了启动这一步啦。

上一步我们已经将Tomcat安装为Windows服务了,以后启动Tomcat就变的十分简单了。

上面我们将Tomcat安装为名为Tomcat8的系统了。只需要执行以下命令就可以启动Tomcat了。

net start Tomcat8

这个命令的执行就不需要必须在Tomcat目录下了。

如果你看到以下信息,就说明启动成功啦:

然后我们再在浏览器访问一下:http://localhost:8080/docs/。如果能看到以下页面就说明你安装成功啦:

遇到的坑

After seeing the article said before Tomcat starts up, visit localhost: 8080 / can see the management interface. But for my case, visit this link only got an error page.

I once thought it was my position does not install. Later discovered that Tomcat has started up (visit localhost: 8080 / docs / can see the normal page).

But I do not understand why the current localhost: 8080 / can not be visited, there is little known partners hope to help me answer in the comments area.

Additional operations 1: unset Tomcat as a Windows Service

If we do not want Tomcat as a Windows service exists, and can execute the following command:
(Win7)

service.bat remove Tomcat8

(win10)

.\service.bat remove Tomcat8

Additional Operation 2: Stop Tomcat

Mentioned above the Tomcat startup. If you want to serve quite down yet? Only you need to do:

net stop Tomcat8

That's all the contents of this article. If you encounter any problems installing the above steps are hoping to return in the comments section, I will give you answers to the best of my knowledge. Of course, if we can easily point a praise much the better.

Also make advertising, personal micro-channel public number: Java Technology station. Welcome to tease
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/unit-fourth/p/12174194.html