Alibaba Cloud Toolkit for Eclipse (Cloud Toolkit) is a free plug-in used for the integrated development environment (IDE). After you develop, debug, and test an application on a local server, you can use this plug-in to deploy the application to an ECS instance.

Prerequisites

Background information

This topic describes how to install Cloud Toolkit in Eclipse in your local server that uses the Windows operating system and use Cloud Toolkit to deploy a Java application to an instance.

Procedure

Step 1: Install Cloud Toolkit

To install Cloud Toolkit in Windows, follow these steps:

  1. Start Eclipse.
  2. On the toolbar, choose Help > Install New Software....
    Install new software
  3. Click Add... in the dialog box that appears.
  4. Enter a name such as Cloud Toolkit for Eclipse, enter the http://toolkit.aliyun.com/eclipse software location, and click Add.
    Edit site information
  5. In the Name column, select Alibaba Cloud Toolkit Core and Alibaba Cloud Toolkit Deployment Tools, clear Contact all update sites during install to find required software in the Details section, and click Next.
    Select components
  6. Click Next.
  7. Select I accept the terms of the license agreement and click Finish.
  8. Click Install anyway.
    Install anyway
  9. Click Restart Now to restart Eclipse.
    Restart Eclipse

Step 2: Set the AccessKey pair

An AccessKey ID is used to identify a user. An AccessKey secret is used to encrypt the signature string and is the key that the server uses to authenticate the signature string. The AccessKey secret must be kept confidential.

To set the AccessKey ID and AccessKey secret, follow these steps:

  1. On the toolbar, choose Window > Preferences.
    Preferences
  2. In the left-side navigation pane, choose Alibaba Cloud Toolkit > Accounts.
  3. Set Access Key ID and Access Key secret, and click Apply and Close.
    Set the account

Step 3: Download and upload the JDK installation package

To download and upload the JDK installation package, follow these steps:

  1. Download Apache Tomcat.
    Note The source code is constantly upgraded and you can obtain the appropriate version as needed.
  2. Download the JDK installation package.
    Note If you download a JDK installation package to a Linux instance, an error will occur when you decompress the package. You can download a JDK installation package for Linux to your computer and then upload it to the instance.
  3. Log on to the ECS console.
  4. In the left-side navigation pane, choose Instances & Images > Images.
  5. In the top navigation bar, select a region.
  6. Find the target instance on the Instances page, and obtain the public IP address of the instance from the IP Address column.
  7. Start WinSCP, use the public IP address to connect to the Linux instance, and upload the JDK installation package to the root directory of the Linux instance.

Step 4: Prepare for installation

To prepare for installation, follow these steps:

  1. Establish a remote connection to the ECS instance. For more information, see Connect to a Linux instance from the console.
  2. Disable the firewall.
    1. Run the systemctl status firewalld command to check the status of the firewall.
      Check the status of the firewall
      • If the firewall is in the inactive state, the firewall is disabled.
      • If the firewall is in the active state, the firewall is enabled. In this example, the firewall is in the active state, so you need to disable the firewall.
    2. Disable the firewall. Skip this step if the firewall is in the inactive state.
      • To temporarily disable the firewall, run the systemctl stop firewalld command.
        Note The firewall is temporarily disabled, and will enter the active state when you restart the Linux operating system next time.
      • To permanently disable the firewall, run the systemctl disable firewalld command.
        Note You can enable the firewall again. For more information, visit the firewalld.
  3. Disable SELinux.
    1. Run the getenforce command to check the status of SELinux.
      Check the status of SELinux
      • If SELinux is in the Disabled state, SELinux is disabled.
      • If SELinux is in the Enforcing state, SELinux is enabled. In this example, SELinux is in the Enforcing state, so you need to disable SELinux.
    2. Disable SELinux. Skip this step if SELinux is in the Disabled state.
      • To temporarily disable SELinux, run the setenforce 0 command.
        Note SELinux is temporarily disabled, and will enter the Enforcing state when you restart the Linux operating system next time.
      • To permanently disable SELinux, run the vi /etc/selinux/config command and press the Enter key. Move the pointer over the line of SELINUX=enforcing, and press the I key to enter the edit mode. Change the SELinux state to Disabled. After that, press the Esc key, enter :wq, and press the Enter key to save and close the SELinux configuration file.
        Note You can enable SELinux again. For more information, visit the Introduction to SELinux.
    3. Restart the system for the changes to take effect.
  4. Create a user named www to run Tomcat.
    useradd www
  5. Create a root directory for the Java web project.
    mkdir -p /data/wwwroot/default
  6. Grant the file permission under the root directory of the website to www.
    chown -R www.www /data/wwwroot

Step 5: Install JDK

To install JDK, follow these steps in the instance:

  1. Create a directory.
    mkdir /usr/java
  2. Decompress the JDK installation package that is jdk-8u191-linux-x64.tar.gz in this example to /usr/java.
    chmod +x jdk-8u191-linux-x64.tar.gz
    tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/java
  3. Configure environment variables.
    1. Run the vi /etc/profile command to open the /etc/profile file.
    2. Press the I key to enter the edit mode.
    3. Add the following lines into the /etc/profile file:
      # set java environment
      export JAVA_HOME=/usr/java/jdk1.8.0_191
      export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
      export PATH=$JAVA_HOME/bin:$PATH
    4. Press the Esc key to exit the edit mode and enter :wq to save and close the file.
  4. Run the source /etc/profile command to load environment variables.
  5. Run the java -version command to check the JDK version.
    If the JDK version information is returned as follows, JDK is installed.JDK installed

Step 6: Install Apache Tomcat

To install Apache Tomcat, follow these steps in the instance:

  1. Run the following commands in sequence to decompress the apache-tomcat-8.5.34.tar.gz package, rename the Tomcat directory, and configure user permissions:
    tar xzf apache-tomcat-8.5.34.tar.gz
    mv apache-tomcat-8.5.34 /usr/local/tomcat/
    chown -R www.www /usr/local/tomcat/
    The /usr/local/tomcat/ directory contains the following files:
    • bin: stores some Tomcat script files, including scripts used to enable and disable the Tomcat service.
    • conf: stores global configuration files for the Tomcat server, including the important files server.xml and web.xml.
    • webapps: the main web publishing directory of Tomcat and stores web application files by default.
    • logs: stores Tomcat log files.
  2. Configure the server.xml file.
    1. Run the cd /usr/local/tomcat/conf/ command to switch to the /usr/local/tomcat/conf/ directory.
    2. Run the mv server.xml server.xml_bk command to rename the server.xml file.
    3. Run the vi server.xml command to open the file.
    4. Press the I key to enter the edit mode.
    5. Add the following code:
      <? xml version="1.0" encoding="UTF-8"? >
      <Server port="8006" shutdown="SHUTDOWN">
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
      <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
      <GlobalNamingResources>
      <Resource name="UserDatabase" auth="Container"
       type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved"
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
       pathname="conf/tomcat-users.xml"/>
      </GlobalNamingResources>
      <Service name="Catalina">
      <Connector port="8080"
       protocol="HTTP/1.1"
       connectionTimeout="20000"
       redirectPort="8443"
       maxThreads="1000"
       minSpareThreads="20"
       acceptCount="1000"
       maxHttpHeaderSize="65536"
       debug="0"
       disableUploadTimeout="true"
       useBodyEncodingForURI="true"
       enableLookups="false"
       URIEncoding="UTF-8"/>
      <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
        resourceName="UserDatabase"/>
      </Realm>
      <Host name="localhost" appBase="/data/wwwroot/default" unpackWARs="true" autoDeploy="true">
      <Context path="" docBase="/data/wwwroot/default" debug="0" reloadable="false" crossContext="true"/>
      <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
      prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
      </Engine>
      </Service>
      </Server>
    6. Press the Esc key to exit the edit mode, enter :wq, and press the Enter key to save and close the file.
  3. Set Java Virtual Machine (JVM) memory parameters.
    1. Run the vi /usr/local/tomcat/bin/setenv.sh command to create a file named /usr/local/tomcat/bin/setenv.sh.
    2. Press the I key to enter the edit mode.
    3. Add the following code:
      JAVA_OPTS='-Djava.security.egd=file:/dev/./urandom -server -Xms256m -Xmx496m -Dfile.encoding=UTF-8'
    4. Press the Esc key to exit the edit mode, enter :wq, and press Enter to save and close the file.
  4. Configure a script to run Tomcat at system startup.
    1. Run the wget https://github.com/lj2007331/oneinstack/raw/master/init.d/Tomcat-init command to download the script.
    2. Run the mv Tomcat-init /etc/init.d/tomcat command to rename the downloaded Tomcat-init file.
    3. Run the chmod +x /etc/init.d/tomcat command to assign the executable permission to the script file.
    4. Run the following command to set the JAVA_HOME startup script:
      Notice The JDK version information in the script must be the same as that of the JDK version you installed. Otherwise, Tomcat will fail to start.
      sed -i 's@^export JAVA_HOME=.*@export JAVA_HOME=/usr/java/jdk1.8.0_191@' /etc/init.d/tomcat                      
  5. Configure Tomcat to automatically start at system startup.
    chkconfig --add tomcat
    chkconfig tomcat on
  6. Start Tomcat.
    service tomcat start

Step 7: Deploy a Java application to the ECS instance

You can use Cloud Toolkit to deploy a Java application to the ECS instance. Then, Tomcat test is displayed when you visit http://Public IP address of the ECS instance:8080. Follow these steps:

  1. In Eclipse, right-click the name of the application project that you want to deploy, and choose Alibaba Cloud > Deploy to ECS... from the shortcut menu.
    Shortcut menu
  2. In the Deploy to Alibaba Cloud dialog box that appears, complete the following settings:
    • Deploy File: Select a deployment method. Select Upload File in this example. If you build the application project by using Maven, select Maven Build.
    • Choose File: Select the file that you want to deploy.
    • Target Deploy ECS: Specify the region where your instance is located and select an instance.
    • Deploy Location: Enter the directory that you deployed on the ECS instance, such as /data/wwwroot/default in this example.
    • Command: Click Select... and click Add... in the dialog box that appears. Enter a command in the field. The ECS instance runs the command automatically after Cloud Toolkit deploys the Java application to the directory on the ECS instance. In this example, enter the service tomcat restart command to restart Tomcat. You can also enter other commands as needed.
    Enter a command
  3. Click Deploy to start deploying the Java application to the ECS instance.
  4. In the Console section of Eclipse, view the progress of the deployment.
    View the progress
  5. Open your browser and enter the http://Public IP address of the ECS instance:8080 URL in the address bar to connect to the ECS instance.
    If the page in the following figure is displayed, the Java application is deployed to the ECS instance by using the Alibaba Cloud Toolkit for Eclipse plug-in.Java application deployed

What to do next

You can modify the Java application in Eclipse, save the code, and use Cloud Toolkit to deploy the modified file to the ECS instance.