Unable to Run Kotlin Application in Eclipse

2019-04-18 03:22发布

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.

6条回答
你好瞎i
2楼-- · 2019-04-18 03:41

This worked for me.... If you go to Window -> Show View -> Navigator It shows you more a physical layout of your workspace rather than the logical view by the Package Explorer. Right click the kotlin file with the main function defined and click Run As -> Kotlin Application. Worked for me, though I'd kill to be able to use a regular run config but such is life.....

查看更多
Anthone
3楼-- · 2019-04-18 03:41

For me it happened only once. I think this is some glitch from the Kotlin plugin, when you first create a Kotlin file and try run it. Try "new Kotlin class" paste the same content and see if it works. After that you should be able to run both files as it happened to me.

查看更多
家丑人穷心不美
4楼-- · 2019-04-18 03:42

Tried with Java 8 (1.8.0_144) and Eclipse Oxygen.1a Release (4.7.1a - build id 20171005-1200) with the following plugin versions:

  Kotlin    0.8.2.v20170314-0957    org.jetbrains.kotlin.feature.feature.group  JetBrains
    kotlin-eclipse-policy   0.8.2.v20170314-0957    org.jetbrains.kotlin.policy.feature.group   JetBrains
    kotlin-weaving-feature  0.8.2.v20170314-0957    org.jetbrains.kotlin.weaving.feature.feature.group  JetBrains

Everything worked as expected, without the need to create a separate workspace and/or use Kotlin File instead of Kotlin Class:

enter image description here

查看更多
淡お忘
5楼-- · 2019-04-18 03:45

I had the same problem, it solved by deleting the JAVA_HOME environment variable.

I have set an old JDK folder that I deleted in the JAVA_HOME environment variable.

查看更多
劫难
6楼-- · 2019-04-18 03:53

Try new Kotlin File instead of Kotlin Class:

example

查看更多
Juvenile、少年°
7楼-- · 2019-04-18 03:53

I got same issues as you. I tried a lot of ways but not work (like uninstall plugin, then install plugin again, delete project and create new project...)

How to fix: I created a new workspace and setup the helloworld project again. I see that class file generated and I can run it normally.

Note that, we create new workspace and not project. What I notice is workspace contain .metadata folder that may have lot of information for Eclipse.

查看更多
登录 后发表回答