Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin and Java project in Eclipse, NoClassDefFoundError, where are the class files?

In this question the basic configuration of Kotlin + Java + Gradle in Eclipse is described. It allows me to create Kotlin code. The Kotlin and Java natures are correctly present. Unfortunately, the code does not run. Not as Kotlin application nor as JUnit test.

When my (i.e. created by me) Kotlin class is called from Java code, it yields a NoClassDefFoundError. When the same test/application is run from Gradle or IntelliJ the code runs correctly.

My investigation thus far has uncovered that the class files in the bin folder are not there to be found when executing.

Using the buildship plugin

The image below shows that the src tree exists. All Java compile classes are in the src tree. The kotlin_bin folder has the correct folders, but no files.

Eclipse bin folder

Using gradlew eclipse and import .project files

This results in the same behavior. I prefer buildship to manage gradle.

Tool versions

I'm using:

  • Eclipse 2019-03 or 2019-06
  • Kotlin eclipse plugin 0.8.17
  • Kotlin-gradle eclipse plugin 0.8.17
  • Buildship plugin 3.1.0
  • Gradle 5.4.1
  • Kotlin 1.3
  • Java 11

Any tips on how to proceed? I would like to be able to run in Eclipse. We're adding a small Kotlin part to the project, I would prefer not to force my team to switch to IntelliJ.

like image 276
Michiel Leegwater Avatar asked Aug 20 '19 14:08

Michiel Leegwater


People also ask

Where do class files go in Eclipse?

If you look in the bin subdirectory, you'll see the class files. Usually eclipse does this for you. If you go to the eclipse build path (right click properties on your project -> build path) and then select 'source', it should show an output folder.

How do I fix Java Lang NoClassDefFoundError in Eclipse?

NoClassDefFoundError error in tomcat,JBoss,WebSphere* NoClassDefFoundError error in servers occurs because the jar is not in the classpath. To fix this, see the complete stack trace and find the jar which contains the jar and try to copy it to the server classpath or application classpath.

How do I add Java class to Kotlin project?

To convert Java code to Kotlin, open the Java file in Android Studio, and select Code > Convert Java File to Kotlin File. Alternatively, create a new Kotlin file (File > New > Kotlin File/Class), and then paste your Java code into that file.


1 Answers

This issue seems to be an issue with the Eclipse plugin. See KE-344. All symptoms seem to match.

like image 52
Michiel Leegwater Avatar answered Sep 26 '22 01:09

Michiel Leegwater