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+.

Prerequisites

Before getting started, the following tools are installed and configured:

Step 1: Create a Tomcat project

  1. Start IntelliJ IDEA.
  2. Choose File > New > Project to create a project.
  3. In the left-side navigation pane, click Spring Initializr and click Next.
  4. Enter the required project information and select War in the Packaging field. After the configuration is complete, click Next.edit demo
  5. On the Dependencies page, click Web, select Spring Web Starter, and then click Next.
  6. Enter a project name and click Finish to complete the creation.

Step 2: Configure an application

  1. Create a controller.
  2. Follow these steps to configure a local environment.
    1. On the Project tab, choose DemoApplication > Edit Configurations.
    2. In the upper-left corner, click the plus sign (+), and choose Tomcat Server > Local.
    3. On the Server tab, select a version of Tomcat 8.5 or later.
    4. On the Deployment tab, choose the plus sign (+) > Artifacts to configure a deployment method.
    5. In the Select Artifacts to Deploy dialog box, select war exploded as a deployment method, and click OK.
  3. Click Execute Maven Goal, Run, or Debug to start the application.
  4. 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

  1. In the right-side navigation pane, click Maven, and choose Demo > Lifecycle > Package to package the application.
  2. 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

  1. On the Overview page, click Create in the upper-right corner of the Last Updated Deployment Environments section.
  2. In the Basic Information step, select Tomcat in the Technology Stack Type field, enter an application name and description, and then click Next.
  3. 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.
  4. 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.

References