Setting Up a Tomcat-based Java Web Environment (Windows)
Overview
Apache Tomcat (or simply Tomcat) is an open-source web server and servlet container developed by the Apache Software Foundation. This section describes how to install and deploy Tomcat on a Windows ECS.
Windows Server 2022, OpenJDK 21, and Tomcat 11 are used as examples.
Prerequisites
- An ECS has been created. For details, see Purchasing an ECS in Custom Config Mode.
- An EIP has been bound to the ECS. For details, see Assigning an EIP.
Procedure
Installing OpenJDK
- Remotely connect to the ECS. For details, see Login Overview (Windows).
- Visit the OpenJDK official website and download the OpenJDK installation package. In this example, OpenJDK 21 is used. You can also select other versions as required. Figure 1 Download the JDK.
- Go to the directory where the downloaded installation package is stored and extract the package to obtain the extracted path. Figure 2 JDK installation path
- Configure environment variables.
- Right-click This PC and choose Properties > Advanced system settings > Environment Variables. Figure 3 Environment variables
- In the System variables area, click New to create a system variable named JAVA_HOME and set the variable value to the extracted JDK path obtained in 3. Click OK to save the system variable. Figure 4 Creating a JDK system variable
- In the System variables area, select Path and click Edit. Create the following two paths:
%JAVA_HOME%\bin %JAVA_HOME%\jre\bin
Figure 5 Creating JDK paths
- Click OK to save the environment variables.
- Right-click This PC and choose Properties > Advanced system settings > Environment Variables.
- Press Win+R to open the Run dialog box, enter cmd to open the command prompt window, and run the following command. If the version information is displayed, the Java JDK has been installed successfully.
java -version
Figure 6 JDK installation completed
Installing Tomcat
- Remotely connect to the ECS. For details, see Login Overview (Windows).
- Visit the Tomcat official website and download the required installation package. In this example, Tomcat 11 is used. You can also select other versions as required. For details about the mapping between Tomcat and JDK, see the official website. Figure 7 Downloading Tomcat
- Go to the directory where the downloaded installation package is stored and extract the package to obtain the extracted path. Figure 8 Tomcat installation path
- Configure environment variables.
- Right-click This PC and choose Properties > Advanced system settings > Environment Variables. Figure 9 Environment variables
- Click New to create a system variable named CATALINA_HOME and set the variable value to the extracted Tomcat path. Then, click OK to save the system variable. Figure 10 Creating a Tomcat environment variable
- In the System variables area, select Path, click Edit, and click New to create the following path:
%CATALINA_HOME%\bin
Figure 11 Creating a Tomcat path
- Click OK to save the environment variables.
- Right-click This PC and choose Properties > Advanced system settings > Environment Variables.
- Configure Tomcat as a Windows service and start it.
- Press Win+R to open the Run dialog box, and then enter cmd to open the command prompt window. Switch to the bin directory of Tomcat and install Tomcat. If the following information is displayed, the installation is successful.
service.bat install
Figure 12 Tomcat installed successfully
- Press Win+R to open the Run dialog box. Enter services.msc and press Enter to open Services.
Right-click Apache Tomcat 11.0 Tomcat11 and choose Properties. In the displayed dialog box, set Startup type to Automatic, and click Start.
Figure 13 Services
Figure 14 Starting Tomcat
- Press Win+R to open the Run dialog box, and then enter cmd to open the command prompt window.
- Add an inbound rule to the security group of the ECS to allow access to the Tomcat port 8080. To enhance security, you are advised to allow access only from specific IP address ranges instead of from all IPv4 addresses (0.0.0.0/0). For details, see Adding a Security Group Rule.
- In the address bar of the browser, enter http://<ECS-EIP>:8080. If the following page is displayed, the Java web environment has been successfully deployed. Figure 15 Access page
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot