【问题标题】:Can't get Kotlin classes in Java maven project to work (Eclipse)无法让 Java maven 项目中的 Kotlin 类工作(Eclipse)
【发布时间】:2017-02-27 22:10:50
【问题描述】:

我有一个 maven (DropWizard) java 项目。我真的很想添加一些 Kotlin 类,但似乎无法这样做。在我的真实项目中,我添加了像 https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources 这样的 maven 配置,但是“普通”java 代码看不到我的 Kotlin 类。既不是 Maven 也不是 Eclipse。

所以我尝试了混合源示例https://github.com/JetBrains/kotlin-examples/tree/master/maven/mixed-code-hello-world。这在 Maven 中有效,但在 Eclipse 中仍然无效。

我在这里错过了什么?

【问题讨论】:

    标签: java eclipse maven kotlin


    【解决方案1】:

    似乎有几个问题。

    Eclipse 无法将src/main/kotlin 识别为源目录。要修复它,请手动将目录添加到类路径:mixed-code-hello-world 的属性 -> Java 构建路径 -> 源选项卡 -> 添加文件夹...

    然后,尝试删除和添加 Kotlin Nature 以重新索引项目中的 Kotlin 文件。为此,请按右键单击项目 -> 配置 Kotlin -> 删除 Kotlin Nature.

    我已经为这些问题创建了票证:

    1. Eclipse does not recognize kotlin source directory
    2. Kotlin plugin does not reindex files after adding source directory

    【讨论】:

    • 感谢您的回复,但似乎没有帮助。
    • 运行Maven>更新项目后,Kotlin性质又回来了,kotlin_bin为空。
    • 要明确一点:您已经删除然后添加了 Kotlin 性质?如果没有帮助,请尝试重建项目(项目 -> 清理)
    • 做了所有这些,但无济于事。
    • 这不是我的主要问题。主要问题是当我使用 Maven 时,我的标准 java 项目没有构建,这完全停止了我的进步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多