SPRING BOOT-KOTLIN: importing a custom java class to a (Kotlin) controller raises java.lang.NoClassDefFoundError

Viewed 52

Got Exception in thread "Thread-2" java.lang.NoClassDefFoundError: com/myproject/services/MyCustomClass and I'm stuck

build.gradle.kts

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.4.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.4.21"
    kotlin("plugin.spring") version "1.4.21"
}

group = "com.myproject"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
    google()
    jcenter()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    runtimeOnly("com.h2database:h2")
    runtimeOnly("mysql:mysql-connector-java")
    testImplementation("org.springframework.boot:spring-boot-starter-test")

    // Third-party plugins
    implementation("net.sf.okapi.lib:okapi-lib-xliff2:1.41.0")
    implementation("org.json:json:20201115")
    implementation("org.jsoup:jsoup:1.13.1")
    implementation("com.sun.xml.dtd-parser:dtd-parser:1.4.3")
    implementation("org.mapdb:mapdb:3.0.8")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "11"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

ProjectController.kt : https://pastebin.com/j4BJzVUp <-- sorry guys. this is to avoid that annoying "your post mostly code" message

When I run the compiled .jar and hit the endpoint above, the class below raises the error. don't know why

MyCustomClass.java

package com.myproject.services;

public class MyCustomClass {
    public MyCustomClass() {
        System.out.println("blabla");
    }
}

I don't know what to do next.

please help

FYI, I'm using the latest IntelliJ

0 Answers
Related