无法在Eclipse中运行Kotlin应用程序 [英] Unable to Run Kotlin Application in Eclipse

查看:467
本文介绍了无法在Eclipse中运行Kotlin应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在Eclipse中创建我的第一个简单的Kotlin项目,我遵循了

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插件
  • 打开Kotlin透视图并创建Kotlin项目
  • 使用main方法在"src"文件夹中创建文件"hello.kt"
  • 右键单击文件>运行方式> Kotlin应用程序
  • 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

但是,我始终在Eclipse控制台中收到以下错误:

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

错误:找不到或加载主类HelloKt

Error: Could not find or load main class HelloKt

我已经为我的项目仔细检查了运行配置,并且确实将"Main class"设置为HelloKt(我100%确信它不存在).另外,当我按下搜索"按钮时,Eclipse唯一找到的项目是HelloKt - (default package)(同样,它不存在).

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文件的代码:

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:

  • 我正在使用其他Eclipse版本(本教程建议使用Luna;我正在使用Mars.2).
  • 我使用的是其他JDK版本(本教程没有建议任何特定版本,但是从图像中我们可以看到它们使用了jdk1.6.0_45,而我使用的是jdk1.7.0_79.
  • 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.

请注意,我使用的是最新版本的Kotlin Eclipse插件,因此与这篇文章.这些是我当前安装中的版本:

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:

  • 科特林0.7.2.v20160930-0748
    • kotlin-eclipse-policy 0.7.2.v20160928-1525
    • kotlin-weaving-feature 0.7.2.v20160928-1525
    • 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?

      更新(2017年5月14日)

      尝试使用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). 问题仍然存在.

      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.

      推荐答案

      尝试使用以下插件版本的Java 8(1.8.0_144)和Eclipse Oxygen.1a发行版(4.7.1a-构建ID 20171005-1200):

      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
      

      一切正常,而无需创建单独的工作区和/或使用Kotlin File代替Kotlin Class:

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

      这篇关于无法在Eclipse中运行Kotlin应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆