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

Prerequisites

  • Java Development Kit (JDK) 1.8 or later is downloaded and installed. For more information, visit 64-bit Java for Windows.
  • Eclipse IDE 4.5.0 or later is downloaded and installed. For more information, visit the Eclipse website. Eclipse IDE 4.5.0 or later is suitable for Java Enterprise Edition (Java EE) developers.
  • An AccessKey pair is created. For more information, see Create an AccessKey pair.
  • An ECS instance is created. For more information, see Create an instance by using the wizard.

    In these examples, a Linux instance of the ecs.c6.large instance type is used.

  • A security group of the Virtual Private Cloud (VPC) type is created. Inbound rules are added to the security group to allow traffic on ports 21, 22, and 80. For more information, see Add security group rules.
  • Windows Secure Copy (WinSCP) or another remote tool that can be used to connect to the Linux operating system is installed.

Background information

This topic describes how to install Cloud Toolkit in Eclipse on your Windows computer and then use Cloud Toolkit to deploy a Java application to an ECS instance.

Procedure

  1. Step 1: Install Cloud Toolkit on your Windows computer
  2. Step 2: Configure an AccessKey pair
  3. Step 3: Download and upload a JDK installation package
  4. Step 4: Make preparations
  5. Step 5: Install JDK
  6. Step 6: Install Apache Tomcat
  7. Step 7: Deploy a Java application to an ECS instance

Step 1: Install Cloud Toolkit on your Windows computer

  1. Start Eclipse on your Windows computer.
  2. In the top navigation bar of the Eclipse window, choose Help > Install New Software...
    Install New Software
  3. Click Add...
  4. Enter a name such as Cloud Toolkit for Eclipse in the Name field, enter http://toolkit.aliyun.com/eclipse in the Location field, and then click Add.
    Edit Site
  5. In the Name column, select Alibaba Cloud Toolkit Core and Alibaba Cloud Toolkit Deployment Tools. In the Details section, clear Contact all update sites during install to find required software. Then, click Next.
    Select components
  6. Click Next.
  7. Select I accept the terms of the license agreement and click Finish.
    You can view the installation progress of Cloud Toolkit in the lower-right corner of the Eclipse window.
  8. While Cloud Toolkit is being installed, the Security Warning dialog box appears. In the Security Warning dialog box, click Install anyway.
    Install anyway
  9. After Cloud Toolkit is installed, the Software Updates dialog box appears. In the Software Updates dialog box, click Restart Now to restart Eclipse.
    Restart Eclipse
    After specific versions of Eclipse are restarted, they must be activated for use by using an activation code. You must obtain an activation code and activate Eclipse on your own.

Step 2: Configure an AccessKey pair

An AccessKey ID identifies a user. An AccessKey secret encrypts the signature string and is the key that the server uses to authenticate the signature string. The AccessKey pair must be kept confidential.

Perform the following operations to configure the AccessKey ID and AccessKey secret.

  1. In the top navigation bar of the Eclipse window, choose Window > Preferences.
    Preferences
  2. In the left-side navigation pane, choose Alibaba Cloud Toolkit > Accounts.
  3. Specify AccessKey ID and AccessKey Secret, and click Apply and Close.
    Configure an account

Step 3: Download and upload a JDK installation package

  1. Download Apache Tomcat. For more information, visit Index of /apache/tomcat/tomcat-8/.
    Note The source code is constantly upgraded and you can obtain the version that is appropriate to your needs.
  2. Download a JDK installation package. For more information, visit Java Downloads.
    Note If you download a JDK installation package for Linux to the instance, an error occurs when you decompress the package. To avoid this error, you can download a JDK installation package for Linux to your computer and then upload the package 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. On the Instances page, find the Linux instance and view its public IP address in the IP Address column.
  7. In WinSCP, use the public IP address to connect to the Linux instance. Then, upload the JDK installation package to the root directory of the instance.

Step 4: Make preparations

  1. Log on to the Linux instance.
  2. Disable the firewall.
    1. Run the systemctl status firewalld command to check the state of the firewall.
      Check the state of the firewall
      • If the firewall is disabled, it is in the inactive state.
      • If the firewall is enabled, it is in the active state. In this example, the firewall is in the active state and must be disabled.
    2. Disable the firewall. Skip this step if the firewall is already disabled.
      • To temporarily disable the firewall, run the following command:
        systemctl stop firewalld
        Note After you run the preceding command, the firewall is disabled. The next time you restart the Linux operating system, the firewall is re-enabled and enters the active state.
      • To permanently disable the firewall, run the following commands in turn.
        1. To disable the running firewall, run the following command:
          systemctl stop firewalld
        2. To stop the firewall service and configure the service not to automatically start on instance startup, run the following command:
          systemctl disable firewalld
        Note After you run the preceding commands, the firewall is disabled. The next time you restart the instance, the firewall remains disabled by default. You can re-enable the firewall. For more information, see Firewalld documentation.
  3. Disable SELinux.
    1. Check the state of SELinux.
      getenforce
      Example command output:Check the state of SELinux
      • If SELinux is disabled, it is in the Disabled state.
      • If SELinux is enabled, it is in the Enforcing state. In this example, SELinux is in the Enforcing state and must be disabled.
    2. Disable SELinux. Skip this step if SELinux is already disabled.
      • To temporarily disable SELinux, run the following command:
        setenforce 0
        Note After you run this command, SELinux is disabled. The next time you restart the Linux operating system, SELinux is re-enabled and enters the Enforcing state.
      • To permanently disable SELinux, run the following command to open the SELinux configuration file:
        vi /etc/selinux/config

        In the /etc/selinux/config file, move the pointer on the SELINUX=enforcing line and press the I key to enter the edit mode. Set SELINUX to disabled. Press the Esc key, enter :wq, and then press the Enter key to save and close the SELinux configuration file.

        Note You can re-enable SELinux. For more information, see Enable or disable 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 website root directory.
    mkdir -p /data/wwwroot/default
  6. Change the owner of the website root directory to www.
    chown -R www.www /data/wwwroot

Step 5: Install JDK

  1. Create a directory.
    mkdir /usr/java
  2. Decompress the JDK installation package.
    In this example, the jdk-8u241-linux-x64.tar.gz JDK installation package is decompressed to the /usr/java directory.
    chmod +x jdk-8u241-linux-x64.tar.gz
    tar xzf jdk-8u241-linux-x64.tar.gz -C /usr/java
  3. Set environment variables.
    1. Open the /etc/profile file.
      vi /etc/profile
    2. Press the I key to enter the edit mode.
    3. Add the following lines to the /etc/profile file:
      # set java environment
      export JAVA_HOME=/usr/java/jdk1.8.0_241
      export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
      export PATH=$JAVA_HOME/bin:$PATH
    4. Press Esc to exit the edit mode. Enter :wq and press the Enter key to save and close the file.
  4. Load environment variables.
    source /etc/profile
  5. View JDK version information.
    java -version
    If JDK is installed, JDK version information is displayed. jdk180241

Step 6: Install Apache Tomcat

  1. In the system root directory, run the following commands in turn.
    1. Decompress apache-tomcat-8.5.53.tar.gz.
      tar xzf apache-tomcat-8.5.53.tar.gz
    2. Move and rename the Tomcat directory.
      mv apache-tomcat-8.5.53 /usr/local/tomcat/
    3. Configure user permissions on the Tomcat directory.
      chown -R www.www /usr/local/tomcat/
    The /usr/local/tomcat/ directory contains the following subdirectories:
    • bin: stores some Tomcat script files, such as those used to enable and disable the Tomcat service.
    • conf: stores various global configuration files of the Tomcat server, among which server.xml and web.xml are the most important files.
    • webapps: serves as the main web publishing directory of Tomcat. It stores web application files by default.
    • logs: stores Tomcat operation log files.
  2. Configure the server.xml file.
    1. Switch to the /usr/local/tomcat/conf/ directory.
      cd /usr/local/tomcat/conf/
    2. Rename the server.xml file.
      mv server.xml server.xml_bk
    3. Open the server.xml file.
      vi server.xml
    4. Press the I key to enter the edit mode.
    5. Add the following content to the file:
      <?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. Create and open the /usr/local/tomcat/bin/setenv.sh file.
      vi /usr/local/tomcat/bin/setenv.sh
    2. Press the I key to enter the edit mode.
    3. Add the following content to the file:
      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 the Enter key to save and close the file.
  4. Configure a script to run Tomcat on system startup.
    1. Download the script.
      Note This script originates from the community and is for reference only. Alibaba Cloud does not make any guarantee, express or implied, with respect to the performance and reliability of the script or the potential impacts of the script operations.
      wget http://raw.githubusercontent.com/oneinstack/oneinstack/master/init.d/Tomcat-init
    2. Rename Tomcat-init.
      mv Tomcat-init /etc/init.d/tomcat
    3. Grant the execute permissions on the /etc/init.d/tomcat file.
      chmod +x /etc/init.d/tomcat
    4. Configure the JAVA_HOME script to run Tomcat on system startup.
      Notice The JDK version in the script must be the same as that you installed. Otherwise, Tomcat cannot start.
      sed -i 's@^export JAVA_HOME=.*@export JAVA_HOME=/usr/java/jdk1.8.0_241@' /etc/init.d/tomcat                  
  5. Configure Tomcat to automatically run on system startup.
    1. chkconfig --add tomcat
    2. chkconfig tomcat on
  6. Start Tomcat.
    service tomcat start

Step 7: Deploy a Java application to an ECS instance

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

  1. In Eclipse, right-click the name of the application project that you want to deploy and choose Alibaba Cloud > Deploy to ECS...
    Deploy to ECS
  2. In the Deploy to Alibaba Cloud dialog box, complete the following settings:
    • Deploy File: Specify a deployment method. In this example, Upload File is selected. If you built the application project by using Maven, select Maven Build.
    • Choose File: Select the file that you want to deploy.
    • Target Deploy ECS: Select a region and an ECS instance.
    • Deploy Location: Enter a directory that you deployed on the ECS instance. In this example, /data/wwwroot/default is used.
    • Command: Click Select... In the dialog box that appears, and then click Add.... Enter a command in the text box. This command is automatically executed after Cloud Toolkit deploys the Java application to the specified directory on the ECS instance. In this example, service tomcat restart is entered to restart Tomcat. You can also enter another command based on your business needs.
    Enter a command
  3. Click Deploy to start deploying the Java application to the ECS instance.
  4. In the Console section of Eclipse, you can view the deployment progress.
    View the progress
  5. Open your browser and enter http://<Public IP address of the ECS instance>:8080 in the address bar to connect to the ECS instance.
    If the Java application is deployed to the ECS instance by using Cloud Toolkit, the information shown in the following figure is displayed. Java application deployment succeeded

What to do next

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