Kotlin not working with Eclipse Workspace Resolution

心不动则不痛 提交于 2019-12-18 06:06:12

问题


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?


回答1:


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.




回答2:


Your dependencies looks good. I haven't find any error.

But Here is a rambling of some theories to you should look into:

  • It could be because of having multiple projects in the workspace.

    It could be having multiple projects in the workspace increases the chances of the issue showing up.

    It could be because other projects have different natures.

    It could be because of how the projects land (sort order, load order, something else?).

    It could be because some logic somewhere is flaky.

    It could be building the project leaves eclipse in an unexpected state.

    It could be because some kind of delta logic thinks there are no changes to no build needs to be attempted because launching the project.

    It could be because the launch mechanism being used is the wrong one.



来源:https://stackoverflow.com/questions/57968100/kotlin-not-working-with-eclipse-workspace-resolution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!