Kevin Zhang
09/27/2022, 6:15 AMmultiplatform + springboot + react
. The application can’t find the javascript file.
I package the js
file into jar using:
tasks.getByName<BootJar>("bootJar") {
val webpackTask = tasks.getByName<KotlinWebpack>("reactBrowserDevelopmentWebpack")
dependsOn(webpackTask) // make sure JS gets compiled first
println(webpackTask.destinationDirectory)
println(webpackTask.outputFileName)
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName))
archiveBaseName.set("${project.name}-with-dependencies")
}
and the jar actually has the js
file. But when i start the springboot application and visit the index page, it report not found error.
@GetMapping("/")
@ResponseBody
fun index() = createHTML().html {
head {
title("Hello,Kevin")
}
body {
div {
id = "root"
}
script(src = "kotlin-fullstack-v2.js"){}
}
}
Is there any fault in my code?Kevin Zhang
09/27/2022, 7:53 AMfrom\into in the bootJar task
copy js files into the target directory:
tasks.getByName<BootJar>("bootJar") {
val webpackTask = tasks.getByName<KotlinWebpack>("reactBrowserDevelopmentWebpack")
dependsOn(webpackTask) // make sure JS gets compiled first
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)){
into("BOOT-INF/classes/static/js/src")
}
archiveBaseName.set("${project.name}-with-dependencies")
mainClass.set("com.kevin.FullStackApplicationKt")
archiveClassifier.set("boot")
}