3

I am trying to find a setup for developing mixed Java and Kotlin applications in Eclipse. Everything seems to work fine for older Versions of Eclipse and that support JDK8. However, for newer Versions and using JDK11, the Kotlin Eclipse plugin does not seem to work as expected.

My setup:

  • Fresh installation of Eclipse 2020-06 IDE For Java and DSL developers
  • Java VM: Open JDK 11
  • Installed Kotlin Plugin for Eclipse 0.8.21
  • Installed AspectJ Development Tools 1.9.6 (appears to be required for the Kotlin plugin to work correctly)

Everything works fine when I create a simple Kotlin Project and add a file hello.kt with the following content:

package hello

fun main() {
    println("Hello World!")
}

I then add a java class Foo.java to the project:

package hello;

public class Foo {
    public void foo() {
        System.out.println("Foo!");
    }
    
}

This still compiles and runs fine. However, as soon as I modify hello.kt and use the Java class, the program does not run anymore. This is my modified hello.kt:

package hello

fun main() {
    println("Hello World!")
    val foo = Foo()
    foo.foo()
}

Compiling still seems to work fine. At least no errors are reported in the IDE. However, when running the application, I get the following error:

Error: Could not find or load main class hello.HelloKt
Caused by: java.lang.ClassNotFoundException: hello.HelloKt

By inspecting the bin directory of the project, I found that in the initial pure Kotlin version of the program, a file HelloKt.class was generated. However, in the mixed Java and Kotlin Version, only Foo.class is generated, but there is no HelloKt.class. This suggests to me that the Kotlin compiler is either not invoked properly, or it fails for some reason without notifying the user.

Any ideas on how this could be fixed? Is this expected to work, or is the Kotlin plugin for Eclipse outdated and broken for newer versions?

  • I am having pretty much exactly the same experience with Eclipse 2020-12. There are other .kt files in my project that don't depend on any Java classes. There are __no__ xxxKt.class files in bin with the mixed .java and .kt files. The other xxxKt.class files are there if I remove the mixed files from the project. – Kenneth Evans Sep 21 '21 at 23:42
  • I also have Java files that are standalone and not accessed by .kt files. Those .class files are also there. The problem seems to be with combining Java with Kotlin. – Kenneth Evans Sep 21 '21 at 23:54

0 Answers0