To use Kotlin, we need to add it to our project: Ĭhange into the directory that was just created by running the following command: cd hellocucumber You should get something like the following result: Project created from Archetype in dir: /cucumber "-DarchetypeArtifactId=cucumber-archetype" \ Open a terminal, go to the directory where you want to create your project,Īnd run the following command: mvn archetype:generate \ Note that the code you provide would be generated as a nested class (inside the script).We’ll start by creating a new project directory with the cucumber-archetype Here's a Java project which demonstrates this (code would be cleaner in Kotlin): to generate a jar file that can then be loaded). KotlinScript can be used to compile Kotlin source code (e.g. I'm not aware of a clean solution for this, Kotlin was not designed to be run like like PHP / JavaScript / Python which just interprets text dynamically, it has to compile to bytecode first before it can do anything on the JVM so in each scenario, you will need to compile that code first in one way or another, whether to bytecode or to javascript and in both cases load it into you application using the Java Classloader or Rhino. Runtime.getRuntime().exec(""" "kotlin code here" > blah.kts | sh""") So once again, you'll have an eval(kotlin-code-string-here) method which will dump the content to a blah.kt file, then you would use a Kotlin2JS compiler to compile it to JavaScript and directly execute the JavaScript inside Kotlin using Rhino which is not great either.Īnother option is to make use of Kotlin Scripting or an external Kotlin compiler (in both cases, the Kotlin compiler will have to start up) and doing something like this will also allow you to execute dynamically, albeit, only on Unix systems. You might want to look at Kotlin Scripting, see Īlternatively, you'll need to write your own eval(kotlin-code-string-here) method which will dump the text inside blah.kt file for example, compile it using an external Kotlin compiler into blah.class then dynamically load those classes into the runtime using the Java Classloader doing something like this: ("圜lass")Īnother no so great option is to make use of Rhino and run JavaScript inside your Kotlin code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |