Skip to content

Commit 6438095

Browse files
committed
WIP
1 parent 0d8d051 commit 6438095

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

README.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
1+
# A minimal Spring Boot project with Kotlin scripting
2+
3+
## Introduction
4+
15
Running Kotlin scripts inside Spring Boot applications is a cool thing.
26

37
But it is very tricky to make it work inside SpringBoot fatjars.
48

9+
## The problem
510
Kotlin cannot load classes from the fatjars.
611

712
Theoretically, a classloader can be configured for Kotlin scripting.
813

914
Unfortunately, this doesn't actually work because the implementation uses its own classloader.
1015

16+
## The solution
1117
The workaround is to unpack the jars used by the scripts.
1218

19+
## This project
1320
This project contains sample code including a gradle setup that implements a minimal project with these requirements.
21+
22+
### Module: application
23+
The Spring Boot application with gradle configuration to unpack the jars.
24+
25+
### Module: business
26+
A simple module with a class that is used by the Kotlin script.
27+
28+
## How to run
29+
Just run:
30+
31+
1. `./gradlew clean build`
32+
2. `java -jar application/build/libs/application-0.0.1.jar`
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package de.micromata.kotlinscripting
22

3-
import Foo
43
import org.springframework.boot.autoconfigure.SpringBootApplication
54
import org.springframework.boot.runApplication
65

76
@SpringBootApplication
8-
class DemoApplication
7+
class DemoApplication {
98

10-
fun main(args: Array<String>) {
11-
runApplication<DemoApplication>(*args)
9+
companion object {
10+
@JvmStatic
11+
fun main(args: Array<String>) {
12+
runApplication<DemoApplication>(*args)
1213

13-
val scriptExecutor = ScriptExecutor()
14-
val result = scriptExecutor.executeScript()
15-
println("Script result: $result")
16-
Foo().bar()
14+
val scriptExecutor = ScriptExecutor()
15+
val result = scriptExecutor.executeScript()
16+
println("Script result: $result")
17+
}
18+
}
1719
}

0 commit comments

Comments
 (0)