In Web+, a Tomcat technology stack includes a collection of environment settings. These settings are applied to Java web applications that run in Tomcat web containers. This topic describes how to develop a simple Tomcat application and deploy the application in Web+.
Step 1: Create a Tomcat project
- Start IntelliJ IDEA.
- Choose File > New > Project to create a project.
- In the left-side navigation pane, click Spring Initializr and click Next.
- Enter the required project information and select War in the Packaging field. After the configuration is complete, click Next.
- On the Dependencies page, click Web, select Spring Web Starter, and then click Next.
- Enter a project name and click Finish to complete the creation.
Step 2: Configure an application
- Create a controller.
- Follow these steps to configure a local environment.
- On the Project tab, choose DemoApplication > Edit Configurations.
- In the upper-left corner, click the plus sign (+), and choose Tomcat Server > Local.
- On the Server tab, select a version of Tomcat 8.5 or later.
- On the Deployment tab, choose the plus sign (+) > Artifacts to configure a deployment method.
- In the Select Artifacts to Deploy dialog box, select war exploded as a deployment method, and click OK.
- Click Execute Maven Goal, Run, or Debug to start the application.
- Open a browser and enter http://localhost:8080 in the address bar to visit the home page of the application.
Step 3: Package the application
- In the right-side navigation pane, click Maven, and choose Demo > Lifecycle > Package to package the application.
- The JAR package is created in the target directory of the project after you package the application, for example, demo-0.0.1-SNAPSHOT.jar. Then, you need to deploy the application in Web+.
Step 4: Create and deploy an application
- On the Overview page, click Create in the upper-right corner of the Last Updated Deployment Environments section.
- In the Basic Information step, select Tomcat in the Technology Stack Type field, enter an application name and description, and then click Next.
- In the Deployment Environment Information step, enter a deployment environment name, select Upload Local Application in the Deployment Package Source field, upload the demo-0.0.1-SNAPSHOT.jar deployment package, and then modify the deployment package version. Click Create with Low Cost Preset.
- In the Creation Complete step, click View Application or Creation Complete to go to the Overview tab of the Application Details page. Click the name of a deployment environment to go to the Overview tab of the Deployment Environment Details page. Then, click the link next to the Public IP Address label to view the homepage of the application.
Attach a database to an application
The method for attaching a database to a Tomcat application is similar to the method for a Java application. For more information, see Add ApsaraDB for RDS instances to the deployment environment of a Java application. An example of how to attach a database is provided in the alibabacloud-webplus-tomcat-demo deployment package.
- For more information about how to deploy an application in the console, see Deploy an application.
- For more information about how to use the CLI tool to create and deploy an application, see Use the CLI to quickly deploy applications.
- For more information about management tasks after you host an application, see Overview of application details.
- For more information about how to manage deployment environments where applications reside, see Deployment environment overview.