Deploy an application to a Windows server using IntelliJ IDEA

更新时间:
复制 MD 格式

Cloud Toolkit lets you deploy applications to servers that use the standard Secure Shell (SSH) protocol. You can quickly deploy an application by selecting a target server in the graphical user interface (GUI) without switching between different O&M tools. This topic describes how to use Cloud Toolkit in IntelliJ IDEA to deploy a local application to a Windows server. You can use either OpenSSH Server or freeSSHd for the deployment configuration.

Prerequisites

Cloud Toolkit is installed and configured. For more information, see Install and configure Cloud Toolkit in IntelliJ IDEA.

Preparations

Configure a Windows server that supports the standard SSH protocol as follows:

Note

You can choose to install either OpenSSH Server or freeSSHd.

  • Install OpenSSH Server. If your remote server runs Windows 10, it may already include the OpenSSH server-side component. If so, you can skip this step. For more information about how to check, see the official document.

    Install PowerShell on the Windows server. For more information, see the official tutorial. If PowerShell is already installed on your server, you can skip this step.

    • For online installation, see the official tutorial.

    • To install offline, follow these steps:

      1. Download the OpenSSH installation package.

        Note

        The installation packages for 64-bit and 32-bit operating systems are different. Download the package that matches your server's operating system.

      2. Extract the installation package to the C:\Program Files\OpenSSH-Win64 path.

      3. Open Command Prompt in the C:\Program Files\OpenSSH-Win64 path. Then, run the following command to install OpenSSH.

        powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1                                       
      4. Run the following commands to configure OpenSSH to start automatically and then start the OpenSSH service.

        sc config sshd start= auto
        net start sshd                
      5. Run the following command in PowerShell to change the default shell to PowerShell.

        New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force                
  • Install freeSSHd as follows:

    1. Download the freeSSHd installation package.

    2. Create a folder on the C drive and rename it to ActTemp.

    3. Open freeSSHd, click the SFTP tab, and set the SFTP home path to C:\ActTemp.

    4. On the Users tab, click Add. In the User properties dialog box that appears, configure the account information.

      Configure the general parameters as follows:

      • Login: Specifies the login name.

      • For Authorization, select Password stored as SHA1 hash.

      • Password: Enter the password.

      • Confirm password: Enter the password again.

      • Allowed operations: Select the shell, SFTP, and Tunneling check boxes.

    5. Configure the default shell. Click the SSH tab and set the Command shell path to C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.

    6. On the Server status tab, start the Telnet and SSH services. The status of the Telnet service changes to Telnet server is running, and the status of the SSH service changes to SSH server is running.

Deploy an application to a Windows server

You can deploy a local application by following these steps:

  1. Import your local application into IntelliJ IDEA.

  2. Add a server.

    1. In the top menu bar of IntelliJ IDEA, choose Tools > Alibaba Cloud > Alibaba Cloud View > Host.

    2. On the Host tab, click Add Host.

    3. In the Add Host dialog box, set parameters such as Host List, Username, Password, and Tag, and then click Add.

      Note

      After setting the parameters, click Test Connection to verify the server connection.

  3. Deploy the application.

    1. In the top menu bar of IntelliJ IDEA, choose Tools > Alibaba Cloud > Deploy to Host....

    2. In the Deploy to Host dialog box, set the deployment parameters and click Run.

      The following section describes the deployment parameters.

      Parameter

      Description

      File

      • Maven Build: If the current project is built with Maven, you can build and deploy it directly.

      • Upload File: If the current project is not built with Maven, or if a packaged deployment file already exists locally, you can select and upload the local deployment file.

      • Gradle Build: If the current project is built with Gradle, select this option to build and deploy.

      Target Host

      Select a tag from the drop-down list, and then select the server for deployment from within that tag.

      Target Directory

      Enter the deployment path on the server, such as c:\server\tomcat\deploy.

      Command

      Enter the application start command, such as c:\server\tomcat\deploy\start.bat.

      Note

      By default, the Command field supports all PowerShell commands. You cannot use DOS commands directly. To use DOS commands, you must run them from a batch script (.bat or .cmd).

Verify the result

After the deployment starts, the deployment logs are displayed in the Console area of IntelliJ IDEA. You can review the logs to verify the deployment result.

You can also log on to the remote server using the built-in terminal. Run the cd command to navigate to the deployment path. Then, run the ls command to check whether the deployment was successful. To log on to the remote server, follow these steps:

  1. At the bottom of the IntelliJ IDEA editor, click the Alibaba Cloud View tab and then the Host View tab.

  2. On the Host View tab, in the Actions column for the target remote server, click Terminal to log on.