Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
838 views
in Technique[技术] by (71.8m points)

jvm - Unable to Run Kotlin Application in Eclipse

In order to create my first, simple Kotlin project in Eclipse, I followed the steps in Getting Started with Eclipse Luna tutorial from Kotlin official website, i.e.:

  • Install Kotlin Plugin for Eclipse from Eclipse Marketplace
  • Open the Kotlin perspective and created a Kotlin Project
  • Created the file "hello.kt" inside the "src" folder with the main method
  • Right-clicked the file > Run As > Kotlin Application

However, I keep get the following error in Eclipse console:

Error: Could not find or load main class HelloKt

I have double-checked the Run Configuration for my project, and it does set the "Main class" as HelloKt (which I'm 100% sure it does not exist). Also, when I hit the "Search" button, the only item that Eclipse finds is HelloKt - (default package) (which, again, does not exist).

For the sake of completeness, find below the code for hello.kt file:

fun main(args: Array<String>) {
    println("Hello, World")
}

I noticed the following divergences between the tutorial and what I did:

  • I'm using a different Eclipse version (the tutorial suggests Luna; I'm using Mars.2).
  • I'm using a different JDK version (the tutorial DOES not suggest any specific version, but from the images, we can see they have used jdk1.6.0_45, while I'm using jdk1.7.0_79.

Note that I'm using the latest version of Kotlin Eclipse Plugin, so this is not the same case as in this post. These are the versions in my current installation:

  • Kotlin 0.7.2.v20160930-0748
    • kotlin-eclipse-policy 0.7.2.v20160928-1525
    • kotlin-weaving-feature 0.7.2.v20160928-1525

Can any of these divergences be the cause of the error while running the application?

Do you see/know any potential cause or known bug regarding this scenario?


UPDATE (May 14th, 2017)

Tried with Eclipse Neon.3 (eclipse.buildId=4.6.3.M20170301-0400), JDK 1.8.0_111, Kotlin 0.8.2.v20170314-0957 (kotlin-eclipse-policy 0.8.2.v20170314-0957, kotlin-weaving-feature 0.8.2.v20170314-0957, Equinox Weaving SDK 1.2.0.201701131634). The problem persists.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try new Kotlin File instead of Kotlin Class:

example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...