Kickstart Kotlin : Jython with Spring Boot

Submitted by Dickens A S on Fri, 03/20/2020 - 07:02

Easily create Kotlin based Jython project from these multiplatform boilerplate Gradle DSL

Run gradle command

  gradle assemble

Run gradle command

  gradle run

Browse http://localhost:8080/index.html

On the screen you will see response from Jython via AJAX

JavaScript libraries are maintained using "webjars"

Spring Boot REST code

class HelloController {
    val interp:PythonInterpreter = PythonInterpreter()
    fun greeting(@RequestParam(value = "name", defaultValue = "World") name:String):Greeting {
        interp.exec("import sys")
        interp.exec("print sys")
        interp.set("a", PyString(name));
        interp.exec("a = \"Hello! \" + a + \", from jython\"")
        var a:PyObject = interp.get("a")
        return Greeting(a.toString())


            $("#logarea").html("jQuery document ready!!<br/>")
            $.get('/greeting?name=dickens',function() {
                console.log("ajax success")
            }).done(function(data) {
                $("#logarea").html($("#logarea").html() + '<br/>' + data.content)
            .fail(function() {
                $("#logarea").html($("#logarea").html() + '<br/>' + "error occured while calling ajax")
            .always(function() {
                console.log("ajax finished")

Source Code

End Of Article

Add new comment