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.:

  • 从Eclipse Marketplace安装用于Eclipse的Kotlin插件
  • 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:

错误:无法找到或加载主类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).

为了完整起见,请查看以下hello.kt文件的代码:

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

我注意到本教程与我所做的工作之间存在以下差异:

  • 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策略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.

推荐答案

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,无需创建单独的工作区和/或使用Kotlin File而不是Kotlin Class:

enter image description here

Kotlin相关问答推荐

通过快捷键手动砍掉功能参数等

始终抛出的函数 - 具有块主体的函数中需要的返回表达式

有什么方法可以要求在 kotlin 中的类型参数上进行注释?

我可以在 Kotlin 中使用接口类型作为构造函数参数吗

kotlin 如何决定 lambda 中的参数名称?

即使 Kotlin 的 `Map` 不是 `Iterable`,它如何以及为什么是可迭代的?

为什么 Kotlin 的 null 安全性不能与局部变量初始化器一起正常工作?

从带有 Room 和 Flows 的 SQLite 表中获取祖先树

Kotlin:查找集合中最常见的元素

如何有效地填充 Gradle Kotlin DSL 中的额外属性?

如何从不同的功能发出流量值? Kotlin 协程

带有迭代器函数的 Kotlin 无限序列

Mockito 的 argThat 在 Kotlin 中返回 null

Kotlin:什么是 kotlin.String!类型

Ktor 在 java.library.path 中没有 netty_transport_native_epoll_x86_64

如何在Kotlin中使用ViewModelProviders

Android Jetpack导航,另一个主机片段中的主机片段

旋转 kotlin 数组

Android Jetpack Compose 中的文本渐变

如何在 spring-boot Web 客户端中发送请求正文?