Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
786 views
in Technique[技术] by (71.8m points)

maven - Kotlin not working with Eclipse Workspace Resolution

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...