JSR223 Usage/Dependencies


#1

Hey!

I’ve stumbled accross the following: http://kotlinlang.org/docs/reference/whatsnew11.html#javaxscript-support and I was highly interested in the script engine part. However, I’m getting an error. I’ve used script engines before and I am somewhat familiar with them, but I was unable to actually get the script engine.

val engine = ScriptEngineManager().getEngineByExtension("kts")!!

This is the code that I used. Running this generates an exception:

Exception in thread "ForkJoinPool.commonPool-worker-2" java.lang.ExceptionInInitializerError at de.arraying.arraybot.managers.ManagerRegistry.registerCommands(ManagerRegistry.kt:33) at de.arraying.arraybot.utils.UtilsStartup.startCommands(UtilsStartup.kt:53) at de.arraying.arraybot.Arraybot$init$procedures$2.invoke(Arraybot.kt:84) at de.arraying.arraybot.Arraybot$init$procedures$2.invoke(Arraybot.kt:28) at de.arraying.arraybot.Arraybot$init$procedures$5$1.doResume(Arraybot.kt:90) at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:54) at kotlinx.coroutines.experimental.DispatchedContinuation$resume$1.run(CoroutineDispatcher.kt:171) at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) Caused by: kotlin.KotlinNullPointerException at de.arraying.arraybot.commands.commands.developer.eval.CommandEval.<init>(CommandEval.kt:33) at de.arraying.arraybot.commands.CommandCollection.<clinit>(CommandCollection.kt:100) ... 12 more

The CommandEval.kt:33 is the line which I have showed above.

I’ve then tried adding additional dependencies, them being:
compile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-script-runtime:$kotlin_version"

Nothing changed after adding these two. I’ve checked out the script engine example, that hasn’t helped me. Neither has a google search to see if anyone else has the problem. So I’m here asking what I’m doing wrong. Am I missing some dependencies? Is my project set up wrong?

Thanks


#2

The example linked in the documentation has a text file in it’s resources directory, ScriptEngineFactory, that specifies the factory class to use:

Do you have such a config file as well?


#3

I did not have one of these files. After implementing it the script engine works. However, I still get this warning:

WARN: Failed to initialize native filesystem for Windows java.lang.RuntimeException: Could not find installation home path. Please make sure bin/idea.properties is present in the installation directory. at com.intellij.openapi.application.PathManager.getHomePath(PathManager.java:95) at com.intellij.openapi.application.PathManager.getBinPath(PathManager.java:132) at com.intellij.util.lang.UrlClassLoader.loadPlatformLibrary(UrlClassLoader.java:321) at com.intellij.openapi.util.io.win32.IdeaWin32.<clinit>(IdeaWin32.java:48) at com.intellij.openapi.util.io.FileSystemUtil.getMediator(FileSystemUtil.java:78) at com.intellij.openapi.util.io.FileSystemUtil.<clinit>(FileSystemUtil.java:70) at com.intellij.openapi.vfs.impl.ZipHandler.setFileStampAndLength(ZipHandler.java:69) at com.intellij.openapi.vfs.impl.ZipHandler$1.createAccessor(ZipHandler.java:51) at com.intellij.openapi.vfs.impl.ZipHandler$1.createAccessor(ZipHandler.java:47) at com.intellij.util.io.FileAccessorCache.createHandle(FileAccessorCache.java:66) at com.intellij.util.io.FileAccessorCache.get(FileAccessorCache.java:52) at com.intellij.openapi.vfs.impl.ZipHandler.getCachedZipFileHandle(ZipHandler.java:112) at com.intellij.openapi.vfs.impl.ZipHandler.createEntriesMap(ZipHandler.java:87) at com.intellij.openapi.vfs.impl.ArchiveHandler.getEntriesMap(ArchiveHandler.java:190) at com.intellij.openapi.vfs.impl.jar.CoreJarHandler.<init>(CoreJarHandler.java:42) at com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem$1.create(CoreJarFileSystem.java:37) at com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem$1.create(CoreJarFileSystem.java:33) at com.intellij.util.containers.FactoryMap.get(FactoryMap.java:57) at com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem.findFileByPath(CoreJarFileSystem.java:50) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.findJarRoot(KotlinCoreEnvironment.kt:374) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.contentRootToVirtualFile(KotlinCoreEnvironment.kt:355) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.convertClasspathRoots(KotlinCoreEnvironment.kt:251) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:197) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:109) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:423) at org.jetbrains.kotlin.cli.jvm.repl.GenericReplChecker.<init>(GenericReplChecker.kt:63) at org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompiler.<init>(GenericReplCompiler.kt:42) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:47) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$replCompiler$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:37) at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplCompiler(KotlinJsr223JvmLocalScriptEngine.kt) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:54) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine$localEvaluator$2.invoke(KotlinJsr223JvmLocalScriptEngine.kt:37) at kotlin.SynchronizedLazyImpl.getValue(Lazy.kt:130) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getLocalEvaluator(KotlinJsr223JvmLocalScriptEngine.kt) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.getReplEvaluator(KotlinJsr223JvmLocalScriptEngine.kt:56) at org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngine.createState(KotlinJsr223JvmLocalScriptEngine.kt:60) at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.createState$default(KotlinJsr223JvmScriptEngineBase.kt:46) at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.getCurrentState(KotlinJsr223JvmScriptEngineBase.kt:53) at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.nextCodeLine(KotlinJsr223JvmScriptEngineBase.kt:44) at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.compileAndEval(KotlinJsr223JvmScriptEngineBase.kt:59) at org.jetbrains.kotlin.cli.common.repl.KotlinJsr223JvmScriptEngineBase.eval(KotlinJsr223JvmScriptEngineBase.kt:31) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at de.arraying.arraybot.commands.commands.developer.eval.CommandEval.onDefaultCommand(CommandEval.kt:65) at de.arraying.arraybot.commands.entities.DefaultCommand.invoke(DefaultCommand.kt:140) at de.arraying.arraybot.commands.Commands$executeCommand$1.doResume(Commands.kt:129) at de.arraying.arraybot.commands.Commands.executeCommand(Commands.kt:89) at de.arraying.arraybot.listeners.ListenerCommand$onGuildMessageReceived$1.doResume(ListenerCommand.kt:39) at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:54) at kotlinx.coroutines.experimental.DispatchedContinuation$resume$1.run(CoroutineDispatcher.kt:171) at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) warning: some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath or use '-Xskip-runtime-version-check' to suppress this warning warning: library has Kotlin runtime bundled into it
I don’t like supressing warnings because they are usually there for a reason, however I have no clue as to how to do what they want me to do.


#4

What is the build system that you use? IntelliJ’s own?

What are the project’s dependencies?


#5

Building I use shadowjar, but this is currently just running the main class. No building involved yet.

Here is my gradle file: https://pastebin.com/pZgMzQvu


#6

So it’s using the IntelliJ build system to compile. What are the project dependencies in IntelliJ project structure?


#7

Artifacts there are none, libraries are as follows:


#8

What is the module classpath?


#9

I don’t know if this is what you mean, lmk if it’s not:

My main class path is de.arraying.arraybot.MainKt (It is a file called Main.kt).