【问题标题】:Unable to run Spring Boot with Kotlin project in Eclipse无法在 Eclipse 中使用 Kotlin 项目运行 Spring Boot
【发布时间】:2019-01-27 05:41:15
【问题描述】:

我安装了Eclipse PhotonKotlin plugin for Eclipse 0.8.6Spring Tools 3.9.5.RELEASE 插件。我按照these 的说明使用向导创建了一个新项目:

然后我创建了一个新的Run Configuration 并按照参考中的说明编辑了主类:

运行项目后,我得到了这个错误:

Error: Could not find or load main class com.kotlinexample.KotlinExampleApplicationKt
Caused by: java.lang.ClassNotFoundException: com.kotlinexample.KotlinExampleApplicationKt

我检查了我的 build.gradlethis 文档,看起来还可以:

buildscript {
    ext {
        kotlinVersion = '1.2.51'
        springBootVersion = '2.0.4.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
    }
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.kotlinexample'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ["-Xjsr305=strict"]
        jvmTarget = "1.8"
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('com.fasterxml.jackson.module:jackson-module-kotlin')
    compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    compile("org.jetbrains.kotlin:kotlin-reflect")
    runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

【问题讨论】:

  • 你的 Kotlin 源码呢?
  • Kotlin plugin for Eclipse 0.8.6

标签: eclipse spring-boot kotlin


【解决方案1】:

我知道我迟到了,但我遇到了同样的问题。右键单击该项目并执行 Configure Kotlin,然后 Add Kotlin Nature 为我完成了这项工作。

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
【解决方案2】:
  1. 尝试创建一个 Maven 项目而不是 Gradle。
  2. 安装 Eclipse Kotlin 插件
  3. 安装最新的 AspectJ 开发工具插件
  4. 通过转到 Preferences 选择 JDK 版本,然后进行以下设置:

首选项 => Kotlin +> 编译器 => JVM 目标版本 = 1.8

首选项 => Kotlin +> 编译器 => JDK 主页 = path_to_your_jdk_installation

  1. 在 Main 类声明之前添加 Kotlin open 关键字,如下例所示:
@SpringBootApplication
open class KotlinExampleApplication { ... }
  1. 使用 maven (mvn clean install) 编译您的项目

  2. 像你一样通过 Spring 仪表板运行它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 2019-11-27
    • 2016-03-12
    • 2020-02-25
    • 2018-05-30
    • 2011-07-30
    相关资源
    最近更新 更多