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.
Using gradlew eclipse and import .project files
This results in the same behavior. I prefer buildship to manage gradle.
Tool versions
I'm using:
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.
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.
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.
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.
This issue seems to be an issue with the Eclipse plugin. See KE-344. All symptoms seem to match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With