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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…