Tutorial: Deployment in IntelliJ IDEA
This tutorial aims to take you step-by-step through configuring and managing deployment of your code to remote hosts, using IntelliJ IDEA.
This functionality relies on the FTP/SFTP/WebDAV Connectivity plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features aren't available, make sure that you didn't disable the plugin.
note
The FTP/SFTP/WebDAV Connectivity plugin is available only in IntelliJ IDEA Ultimate.
Press CtrlAlt0S to open the IDE settings and then select Plugins.
Open the Installed tab, find the FTP/SFTP/WebDAV Connectivity plugin, and select the checkbox next to the plugin name.
Make sure that:
You are working with IntelliJ IDEA version 15.0 or later. This tutorial is prepared with IntelliJ IDEA 2016.1.
You have access right to a remote host you want your code to be deployed on.
Also note that this tutorial is created on Windows 10 and makes use of the default keyboard shortcuts scheme. If you are working on a different platform, or use another keyboard scheme, the keyboard shortcuts will be different.
Press CtrlAlt0S to open the IDE settings and then select Build, Execution, Deployment | Deployment.
Alternatively, go to Tools | Deployment | Configuration....
Click
and select the type of the server you want to create (in our case, it is Local or mounted folder).
In the Create New Server dialog that opens, type the server name and click OK.
The new server is added, but it is still void... It only shows the Web server URL http://localhost, where you will actually browse your uploaded files.
Select the directory where the project files will be uploaded. In our case, this is the C:
![Deployment Connection Tab Deployment Connection Tab](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_connection_tab.png)
Next, switch to the Mappings tab. By default, the Local path field contains the path to the project root. However, you can select any other directory within your project tree. Let's assume the default value.
In the Deployment path field (which is by default empty), specify the folder on your server, where IntelliJ IDEA will upload data from the folder specified in the Local path field: in this example, it's ij\MetersToInchesConverter. This path is specified relative to the web server root folder, which is C:
Finally, accept the default / value for Web path:
![Deployment Mapping Tab Deployment Mapping Tab](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_mapping_tab.png)
After you apply the changes, the server is ready to use.
To make sure your server is up and running, select Tools | Deployment | Browse Remote Host in the main menu, and the Remote Host tool window appears on the right of the IntelliJ IDEA window:
![Remote Hosts tool window Remote Hosts tool window](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_remote_host.png)
Next, let's perform some actions, and see what happens.
First, let's upload one of the files to the remote server.
In the Project tool window, right-click a file you want to upload. In our case, let it be the file MetersToInchesConverter
. From the context menu, choose Upload to MyRemoteServer, and see the upload results.
![Deployment upload Deployment upload](https://resources.jetbrains.com/help/img/idea/2023.3/ij_deployment_upload.png)
You can also upload contents of each directory within your project. For example, right-click the parent directory of the MetersToInchesConverter
, namely, src
and choose Deployment | Upload to MyRemoteServer from the context menu. We now have the entire directory uploaded to the server:
![Deployment File Transfer Deployment File Transfer](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_file_transfer.png)
There is a local and a remote copy of the file MetersToInchesConverter
, and they are identical. Let's modify the local version.
To do that, place the caret at the method declaration, and press CtrlAltShift0T (or choose Refactor | Refactor This from the main menu). The popup menu shows all refactorings, available in the current context. Let's choose Rename refactoring, and rename a method:
![Rename method Rename method](https://resources.jetbrains.com/help/img/idea/2023.3/ij_deployment_rename.png)
Perform refactoring and see the method name and its usage changed.
Now we've changed the local version. Let's make sure IntelliJ IDEA knows about these changes. To do that, go to the Remote host tool window tool window, and right-click MetersToInchesConverter
. From the context menu, choose Compare with Local Version. IntelliJ IDEA opens the Diff Viewer.
![Diff viewer Diff viewer](https://resources.jetbrains.com/help/img/idea/2023.3/ij_deployment_diff_viewer.png)
In the Remote host tool window tool window, right-click the file MetersToInchesConverter
, and choose Download from here in the context menu. IntelliJ IDEA shows a warning:
![Deployment download warning Deployment download warning](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_download_warning.png)
Click Continue:
![Deployment download file transfer Deployment download file transfer](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_download_file_trandfer.png)
You can also download an entire directory, if it has been previously uploaded to the server. For example, if you click the parent src directory and choose the same command, all nested files will be downloaded from the server.
Make a preliminary step - rollback the changes to the MetersToInchesConverter
file Ctrl0Z. You again see the class MetersToInchesConverter
with the renamed method.
Next, click MetersToInchesConverter
, and in the main menu choose Tools | Deployment | Sync with Deployed to MyRemoteServer:
![Deployment sync Deployment sync](https://resources.jetbrains.com/help/img/idea/2023.3/ij_deployment_sync.png)
IntelliJ IDEA shows the Diff Viewer, where you can accept individual changes or reject them.
When you need to have the exact same files on the server as in an IntelliJ IDEA project, automatic upload can be of help. Automatic upload means that whenever a change occurs in the IDE, it will be deployed to the default deployment server.
A deployment server is considered default if its settings apply by default during automatic upload of changed files. To define a deployment server as the default one, follow these steps:
Choose the desired server on the Deployment page (in our case, MyRemoteServer). You can open this page it two possible ways: either Settings | Build, Execution, Deployment | Deployment, or Tools | Deployment | Configuration from the main menu.
Click
.
tip
You can also click the Default Deployment Server widget in the IntelliJ IDEA status bar and select the desired server or server group from the popup menu.
As soon as the default server is set, you can make upload to this server automatic. This can be done in the following two ways:
Open the deployment Options
(Settings | Deployment | Options or Tools | Deployment | Options from the main menu), and in the Upload changed files automatically to the default server field choose Always, or On explicit save action. The difference between these two choices is explained in the field description.
In the main menu, go to Tools | Deployment | Automatic upload. Note that automatic upload in this case is performed in the Always mode.
It is worth noting that the Always mode is not recommended for deploying to production: incomplete code can be uploaded while developing, potentially breaking the production application.
By default, IntelliJ IDEA also uploads the files if they are changed by some external process, such as a VCS branch change, compilation of SASS or LESS, or a File Watcher. To change this behavior and skip external changes, set Upload changed files to the default server to Always and select the Skip external changes checkbox:
![Skip external changes Skip external changes](https://resources.jetbrains.com/help/img/idea/2023.3/deployment_options_external_changes.png)
Now that you have a deployment server all set up, you can export the server configuration settings and then import them on another computer.
Select File | Manage IDE Settings | Export Settings from the main menu.
In the Export Settings dialog that opens, make sure that the WebServers checkbox is selected and specify the path to the target archive.
Select File | Manage IDE Settings | Import Settings from the main menu.
Select the ZIP archive that contains your settings in the dialog that opens.
Select the settings you want to apply in the Select Components to Import dialog that opens and click OK.
Congrats! You've passed this very basic tutorial and performed the following tasks:
Created and configured a server of your own.
Uploaded and downloaded files and folders.
Compared local and remote versions.
Configured the server as default.
Enabled automatic upload of external changes.
Thanks for your feedback!