English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Kotlin Eclipse Environment Setup

This tutorial demonstrates how to install the Kotlin development environment in Eclipse and create a simple Kotlin Hello World application.

set up the environment

    We assume you have already installed Eclipse. If not, you can install it from the download page (http://www.eclipse.org/downloads/ ). It is recommended to use “”package. To work properly4.6) or higher version.

    This tutorial will use Eclipse Neon. For instructions on how to compile and run Kotlin applications using the command line compiler, please refer tousing the command line compiler.

    It is recommended to use Eclipse Marketplace Install Kotlin plugin. Open Eclipse and select Help -> Eclipse Marketplace…  menu and search Kotlin plugin:

    As shown in the figure above, click the “Install”to install “Kotlin Plugin for Eclipse 0.8.2”plugin.

    The old way was to directly use the update site:

http://dl.bintray.com/jetbrains/kotlin/eclipse-plugin/last/

    After Eclipse restarts, you can check that the Kotlin plugin is installed correctly by opening the Kotlin perspective in the main menu:

Window -> Open Perspective -> Other…as shown below - 

Create a new project

    Now you are ready to create a new Kotlin project. Open Eclipse and select: File -> New -> Kotlin Project .

    Create a name of:kotlinan empty project where you can write Kotlin code for JVM (JavaScript is not supported for JavaScript). From the perspective of Eclipse, this project is also a Java project, but it is configured with Kotlin properties, which means it has Kotlin Builder and Kotlin runtime library references. The advantage of this solution is that if needed, we can continue to add Java classes to the project, mixing and matching Kotlin and Java code.

    A new Kotlin project package resource manager should look similar to the following content:

    Now you cansrcfolder to create a new Kotlin file.

    If the '.kt”extension, Eclipse will automatically add it.

    After creating a file, proceed to write the main program, which is the entry point of the Kotlin application. We can simply inputmainPress 'Enter' to automatically complete.

    Finally, add a simple Kotlin code to print the message:

/**
 * Created By oldtoolbag.com
 *
 *@link https://www.oldtoolbag.com/kotlin/
 *
 **/
fun main(args: Array<String>) {
    println("Hello, World!")
}

Run Application

    The simplest way to run the application is to right-click on the main file and select the option from the pop-up menu:Run As -> Kotlin Application .

    If everything goes well, the console window will open automatically and display the results - 

    The first Kotlin application has been successfully run in Eclipse.