I have a Maven-based webapp with multiple "local" Maven dependencies (i.e. the dependencies are themselves projects that are maintained in the same Eclipse workspace as the main app).
I recently rewrote one of the dependencies from Java to Kotlin. Here are the relevant bits from the Kotlin project's pom.xml
:
<properties>
<kotlin.version>1.3.50</kotlin.version>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
<project.reporting.outputEncoding>ISO-8859-1</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version><!--$NO-MVN-MAN-VER$ -->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
When I try to start the application in Tomcat inside Eclipse I get the error:
22:40:22 SEVERE: Context initialization failed
[...]
Caused by: java.lang.NoClassDefFoundError: ... (one of my classes from the new project)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
I have executed a number of troubleshooting steps and determined beyond any doubt that the problem is caused by having Kotlin in the dependency project, i.e. if I restore the Kotlin project to the original Java project, everything works again.
What can I do to fix this problem using the latest versions of Eclipse, Kotlin, Maven, Tomcat, and m2e-wtp?
TEMPORARY WORK-AROUND
I can get the app to work again by going Project menu -> Maven -> "Disable Workspace Resolution" and then manually going to each dependency project and doing a Maven -> install.
This is quite unsatisfactory as a lot of developer productivity features are lost when Workspace Resolution is disabled. So I'll keep the question open for now and offer a bounty in the hopes of a more permanent fix.
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