File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed
application/src/main/kotlin/de/micromata/kotlinscripting Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change
1
+ # A minimal Spring Boot project with Kotlin scripting
2
+
3
+ ## Introduction
4
+
1
5
Running Kotlin scripts inside Spring Boot applications is a cool thing.
2
6
3
7
But it is very tricky to make it work inside SpringBoot fatjars.
4
8
9
+ ## The problem
5
10
Kotlin cannot load classes from the fatjars.
6
11
7
12
Theoretically, a classloader can be configured for Kotlin scripting.
8
13
9
14
Unfortunately, this doesn't actually work because the implementation uses its own classloader.
10
15
16
+ ## The solution
11
17
The workaround is to unpack the jars used by the scripts.
12
18
19
+ ## This project
13
20
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`
Original file line number Diff line number Diff line change 1
1
package de.micromata.kotlinscripting
2
2
3
- import Foo
4
3
import org.springframework.boot.autoconfigure.SpringBootApplication
5
4
import org.springframework.boot.runApplication
6
5
7
6
@SpringBootApplication
8
- class DemoApplication
7
+ class DemoApplication {
9
8
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)
12
13
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
+ }
17
19
}
You can’t perform that action at this time.
0 commit comments