diff --git a/compiler/preloader/src/org/jetbrains/kotlin/preloading/Preloader.java b/compiler/preloader/src/org/jetbrains/kotlin/preloading/Preloader.java index 8cb1f2d39b7..35378ad709f 100644 --- a/compiler/preloader/src/org/jetbrains/kotlin/preloading/Preloader.java +++ b/compiler/preloader/src/org/jetbrains/kotlin/preloading/Preloader.java @@ -63,6 +63,8 @@ public class Preloader { Class mainClass = preloaded.loadClass(options.mainClass); Method mainMethod = mainClass.getMethod("main", String[].class); + Thread.currentThread().setContextClassLoader(preloaded); + Runtime.getRuntime().addShutdownHook( new Thread(new Runnable() { @Override diff --git a/compiler/testData/launcher/helloWorld.kts b/compiler/testData/launcher/helloWorld.kts new file mode 100644 index 00000000000..436aded6c6c --- /dev/null +++ b/compiler/testData/launcher/helloWorld.kts @@ -0,0 +1,3 @@ +package test + +println("Hello!") diff --git a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt index 58c7762f91a..f548cc463a5 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/LauncherScriptTest.kt @@ -79,6 +79,15 @@ class LauncherScriptTest : TestCaseWithTmpdir() { ) } + fun testKotlincJvmSimpleScript() { + runProcess( + "kotlinc-jvm", + "-script", + "$testDataDirectory/helloWorld.kts", + expectedStdout = "Hello!\n" + ) + } + fun testKotlincJsSimple() { runProcess( "kotlinc-js",