Reputation: 1180
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.
Upvotes: 8
Views: 2248
Reputation: 3
since i branch my project ,then refactor project name suit next feature. then my project can't find kotlin class.i search google and stackoverflow no effect. i diff project with scm HEAD version, discover the differece in
.project
<linkedResources>
<link>
<name>kotlin_bin</name>
<type>2</type>
<locationURI>org.jetbrains.kotlin.core.filesystem:/**YOUR_PROJECT**/kotlin_bin</locationURI>
</link>
</linkedResources>
then i fix project name in .project file. it was fixed after rebuild
Upvotes: 0
Reputation: 1180
This issue seems to be an issue with the Eclipse plugin. See KE-344. All symptoms seem to match.
Upvotes: 2
Reputation: 6188
Typically, when you get a NoClassDefFoundError
it means that the class loader cannot find your classes because your class "disappeared". In Eclipse, this is typically fixed with a simple "Clean Project" to force rebuilding. On the other hand, ClassNotFoundException
means something went wrong with your classpath. If cleaning the project and rebuilding doesn't work, I think it might still be possible something could be wrong with your classpath. To check your classpath in Eclipse, change to the Navigator View and open your .classpath
file (see image below).
Then, check your classpathentry
nodes to see "output" path. Your .classpath
should contains mappings for your source location, your output location (where compiled classes reside), as well as references to your JRE container and any libraries imported by the project. Make sure all of these entries are correct.
My guess is that your classpath is not right. To fix, follow these instructions: https://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html. One of those suggestions should work.
Upvotes: 0