[Java] Deploy Java application developed in IntelliJ IDEA environment to Alibaba Cloud ECS instance

2 minute read

This tutorial demonstrates how to deploy a Java application developed in a local IntelliJ IDEA environment to a Alibaba Cloud ECS instance.

*This blog is a translation from the English version. The original can be confirmed from here. Some machine translations are used. If you have any translation errors, we would appreciate it if you could point them out. *

image.png

Develop application locally

Whether you compile a Java application running in the cloud or a Java application running locally, the coding is the same. So, in this article, I will explain the deployment method using a Java Servlet for printing “Hello World” on a web page as an example.

image.png

public class IndexServlet extends HttpServlet {
    private static final long serialVersionUID = -112210702214857712L;

    @Override
    public void doGet( HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        // Demo: Use Alibaba Cloud Toolkit to modify the code of a local application and deploy the application to the cloud.
        writer.write("Deploy from alibaba cloud toolkit. 2018-10-24");
        return;
    }
    @Override
    protected void doPost( HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        return;
    }}

This link.

The code above is a standard Java project for displaying the string “Hello World” on a web page.

Install plugin

Alibaba Cloud provides Intellij IDEA based plugins for efficiently deploying applications written in local IDE to ECS instances.

Plugin URL: https://www.aliyun.com/product/cloudtoolkit_en

The installation process for this Intellij IDEA-based plugin is similar to a generic plugin, so we won’t go into detail here.

Plug-in preferences

After installing the plugin, click the Alibaba Cloud icon in the toolbar as shown below.

image.png

When the following page appears, set the AK and SK of your Alibaba Cloud account, and the setting of the preferences is completed (If you are using a RAM user account, enter the AK and SK of the RAM user. ).

image.png

Deploy the application

image.png

Right-click the project name in IntelliJ IDEA and select Alibaba Cloud >Deploy to ECS from the shortcut menu. The following deploy screen will be displayed.

image.png

Deploy in the ECS dialog box, set the deployment parameters, and click Deploy to complete the initial deployment.

Placement parameter description

Deployment file: You have two options.

  • Maven Build: If you are using Maven to build your current project, you can use the Alibaba Cloud Toolkit to build and deploy your application directly.
  • File Upload: If you’re not using Maven to build your current project, or if you already have a locally packaged deployment file, you can select a local deployment file and upload it directly.
  • Select ECS to deploy: Select a region from the drop-down list and select the ECS instance to deploy to that region.
  • Specify deployment destination: Enter the deployment path on the ECS instance.
  • Command: Enter the application start command. This parameter specifies the command that will be executed after the application package is deployed. For Java programs, this is usually the Tomcat start command.

Alibaba Cloud is the No. 1 (2019 Gartner) cloud infrastructure operator in the Asia-Pacific region with two data centers in Japan and more than 60 availability zones in the world. Click here for more information on Alibaba Cloud. Alibaba Cloud Japan Official Page