I want to separate some generic code from my kotlin script file so that it can be reused.
I did this:
// MyLib.kt
package myLib
fun say_hello(name : String)
{
println("hello $name")
}
I compiled this file to create a jar file:
kotlinc myLib.kt -include-runtime -d myLib.jar
Then I created a script file:
// myScript.kts
import myLib.*
say_hello("Arvind")
But i can not compile the script file as it neither recognizes myLib package nor say_hello() function.
What is the correct way to do this.
Question Update: I am using kscript to run my script. Typing a lot e.g.,
kotlin -cp myLib.jar myScript.kts
every time I have to run the script, thus defeats the motive of using kscript.
Is not there any way so that I need not give path of jar every time command line. Instead I want to use it in a kscript way, i.e.
./myScript