#1059: JarExtractor.kt

projectforge-business/src/main/kotlin/org/projectforge/business/scripting/kotlin/JarExtractor.kt Fat JAR Classpath Workaround, projectforge-business/src/main/kotlin/org/projectforge/business/scripting/kotlin/JarExtractor.kt 128 lines · 81 code · 35 comments · 12 blank
Internal singleton solving the Kotlin scripting classpath problem in Spring Boot fat JARs. Kotlin scripts cannot access classes bundled in a fat JAR directly. This extractor copies required JARs (projectforge, plugins, merlin, poi) from the fat JAR to a temp directory and provides them as a URLClassLoader for the scripting engine.

Architecture

Detection

Checks whether the code source location starts with "jar:", indicating execution from a fat JAR. If not (e.g., running in IDE), skips extraction and uses the current classpath.

Extraction Process

  1. Creates ProjectForge-extracted-jar temp directory, deleting any previous copy.
  2. Opens the fat JAR with JarFile.
  3. Iterates entries; for each .jar file matching the configured regex patterns (projectforge-business, projectforge-common, poi, poi-ooxml, merlin-core, and plugin jars), extracts to the temp directory.
  4. Builds classpathFiles list and classpathUrls array for use by URLClassLoader.

Combat History

The git history shows extensive struggles (commits de4d8d2af, 302470ef9, 7617cf5da, 31545575d) to get Kotlin scripting working in the fat JAR. Multiple approaches were tried before settling on JAR extraction.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
b0058e39e WIP
0c7685b60 WIP: gradle...
921638f43 WIP