Getting Started with Eclipse Luna
Author | Nikolay Krasko |
Last Updated | 28 March 2015 |
Setting up the environment
We’re assuming Eclipse is installed. If not, it can be download from the download page. The “Eclipse IDE for Java Developers” bundle is recommended. For correct functioning, Eclipse Luna S22 (4.4.2) or later is required.
We recommend installing Kotlin plugin from Eclipse Marketplace. One option is to drag-and-drop this button into a running Eclipse window:
Alternatively, use the Help -> Eclipse Marketplace… menu and search for Kotlin plugin:
A more old-fashioned way is using an update site directly:
https://dl.bintray.com/jetbrains/kotlin/eclipse-plugin/last/
Once Eclipse has been restarted, we can check to make sure the Kotlin plugin is installed correctly, by opening the Kotlin perspective
in main menu Window -> Open Perspective -> Other...
Creating a new project
Now we are ready to create a new Kotlin project.
Select File -> New -> Kotlin Project to proceed.
An empty project will be created which is ready for writing Kotlin code that targets the JVM (JavaScript is not supported yet). The project created, from the Eclipse point of view, is also a Java project but configured with Kotlin nature, meaning it has the Kotlin Builder and reference to the Kotlin Runtime Library. Great thing about this solution is that we can continue adding Java classes to the project, mixing and matching Kotlin and Java code if required.
A fresh Kotlin project Package Explorer should look something similar to the following:
We can now create a new Kotlin file under the source folder.
IF omitting the “.kt” extension in file name, Eclipse will add it automatically
Once we have the file created, we need to type the main routine, which is the entry point to a Kotlin application. We can simply type main, invoke completion and hit ‘Enter’
Finally we add a simple line of Kotlin code to print the message:
Running the application
The easiest way to run the application is to do a right-click somewhere in the main file and select Run As -> Kotlin Application
If everything has gone well, the console window output should automatically open, showing the results.
We now have our first Kotlin application running in Eclipse.