As a Java backend programmer (or preparing to become a Java backend programmer), familiarity with Tomcat is essential.
Most of the time, though, Tomcat runs on Linux servers.
However, the daily local development and debugging is unavoidable to install a Tomcat on our Windows computer.
This article will document the installation of Tomcat and some of the bugs encountered.
Step 1: Tomcat download
The first step is to get a Tomcat installation package.
Here are the official download addresses for Tomcat7,8,9.
- Tomcat 9
- Tomcat 8
- Tomcat 7Pay attention to download software as far as possible to download the official website (after all, Tomcat is free).
Let’s use Tomcat8 as an example (because that’s the version I’m using, for laziness!).
Click Tomcat8 above to go to the Tomcat8 download page. Select the corresponding ZIP package based on whether your system is 32-bit or 64-bit. (Yes,Tomcat supports direct decompression installation, which is very convenient) as shown in the following picture:
After downloading it, we can decompress it. For example, I unzip to the following directory:
And here we are, step one!
Step 2: Install
After downloading it, there was very little we needed to do to get Tomcat up and running. The installation step is mainly about setting environment variables. There are two environment variables to set — JAVA_HOME and CATALINA_HOME.
JAVA_HOME is the Java installation directory. What, you said you haven’t installed the JDK yet? Go ahead and download one. For example, my JDK is installed in the following location:
Tomcat is installed in the following locations:
So I set JAVA_HOME to D:\Program Files\Java\jdk1.8.0_211.
Set CATALINA_HOME to D: Program Files\apache-tomcat-8.5.50
The details are shown in the figure below:
As for setting system environment or user variables, you can do either. The user environment variable that I set here.
That’s it, isn’t it getting easier?
Step 3: Set as Windows service
In fact, as the above two steps to start Tomcat. However, for future convenience, we will directly set Tomcat as a Windows service.
In this case, you need to run service.bat in the Tomcat bin directory in the command prompt window. According to the normal practice, we need to enter the tomcat bin directory step by step through the CD command, which is very troublesome.
So, here’s a little trick:
Open the Tomcat installation directory, go to the bin folder, hold down Shift and right click, then the menu will appear “Open command prompt here” (Windows 7) or “Open PowerShell window here”.
Then we just need to execute the following command:
service.bat install Tomcat8
Copy the code
You can set Tomcat as a Windows service. In this case, Tomcat8 is the service name specified by us. This name can be arbitrarily chosen, but I prefer to call it Tomcat8.
Note for Windows 10, write:
.\service.bat install Tomcat8
Copy the code
My execution is as follows:
Tes service ‘Tomcat8’ has been installed. That means we installed successfully!
The output also shows that the JAVA_HOME and CATALINA_HOME Settings we set earlier also work.
Step 4: Boot up
Finally the boot up step.
Since we installed Tomcat as a Windows service in the previous step, starting Tomcat will be much easier.
Above we installed Tomcat as a system named Tomcat8. Just execute the following command to start Tomcat.
net start Tomcat8
Copy the code
This command does not need to be executed in the Tomcat directory.
If you see the following information, the startup is successful:
Then we could access to the browser: http://localhost:8080/docs/. The installation is successful if you can see the following page:
In the pit of
After Tomcat is started, go to localhost:8080/ to see the admin interface. But in my case, a visit to the link resulted in an error page.
At one point, I thought IT was my mounting position. Tomcat is up and running (visit localhost:8080/docs/ you can see the normal page).
I am not sure why localhost:8080/ cannot be accessed. I hope you can help me in the comments section.
Additional Operation 1: Cancel setting Tomcat as Windows service
If we don’t want Tomcat to exist as a Windows service, we can run the following command:
service.bat remove Tomcat8
Copy the code
(win10)
.\service.bat remove Tomcat8
Copy the code
Additional operation 2: Stop Tomcat
The startup of Tomcat was mentioned above. What if you want to survive the service? Just execute:
net stop Tomcat8
Copy the code
That’s all for this article. If you have any problems with the installation, please feel free to reply in the comments section. I will do my best to answer them. Of course, it would be even better if people just liked it.
Another advertisement, personal wechat public number: Java technology station. Welcome to liao