# Kotlin and Vert.x

**URL:** <https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580>\
**Category:** Uncategorized\
**Created:** [July 17, 2012, 7:42am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580 "2012-07-17T07:42:35Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [July 19, 2012, 8:42am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/21 "2012-07-19T08:42:04Z")

</div>

Sorry, it's still not working. Compiling with mvn I get this exception:

> java.lang.UnsupportedClassVersionError: org/vertx/java/core/Vertx : Unsupported major.minor version 51.0

I've imported the pom into Idea, but then I get same error when I run&nbsp;&nbsp;org.vertx.kotlin.examples#Main. I'm using M2, maybe the problem is due to that thing, but I'm guessing Maven compilation would have downloaded the right kotlin version (M1?)

---

<div class="post-metadata">

**Author:** ![jstrachan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstrachan/32/1559_2.png) [@jstrachan](https://discuss.kotlinlang.org/u/jstrachan)\
**Post date:** [July 19, 2012, 8:54am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/22 "2012-07-19T08:54:26Z")

</div>

Are you using Java 6? I think Vertx uses Java 7

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [July 19, 2012, 9:14am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/23 "2012-07-19T09:14:03Z")

</div>

Yes, Java 6. Ok. I'll setup 7 and retry... I really what to trythis project vertex , appears to be easy to use then Netty (which I used in [kweb](https://github.com/parroit/kweb.git)) but still powerful.

And I think we should team-up to concentrate our Kotlin web-framework efforts in a unique direction…

BTW, did you success injecting Kotlin languange in HTML to get autocompletion and error checking in views?

I understand the process is a bit fragile by now, so we thought  
to port the sample views to kool.template… maybe I’ll stress you more in near future 😛

---

<div class="post-metadata">

**Author:** ![jstrachan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstrachan/32/1559_2.png) [@jstrachan](https://discuss.kotlinlang.org/u/jstrachan)\
**Post date:** [July 19, 2012, 9:58am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/24 "2012-07-19T09:58:00Z")

</div>

:) Agreed.

vert.x is looking like a great project & framework for the container/platform/runtime/controller stuff.

On the subject of templating; there are many approaches (we explored many of them in [scalate](http://scalate.fusesource.org/) BTW). With Kotlin specifically the options as I see them are:

1. an internal typesafe DSL for Kotlin (e.g. [Kool Templates](http://kool.io/templates.html)) which can be used on the client in JS or on the server and generates some tree structure (e.g. W3C DOM so its easy to update the DOM in place)
2. multi-line Strings with $ expressions in regular Kotlin files (once we can use StringTemplates to [properly escape HTML](http://youtrack.jetbrains.com/issue/KT-1565) and ideally when we can use [IDEA Language Injection for Kotlin](http://youtrack.jetbrains.com/issue/KT-2428) to perform HTML validation inside the template).
3. external DSLs which are not valid Kotlin source files and need some compile step/cache/reload & IDEA plugins/configurations to allow decent editing

For (3), external DSLs there are various options. One is the Razor/Play style of template where expressions are embedded using some syntax (e.g. @). Another is things like [Jade](http://scalate.fusesource.org/documentation/jade.html). Though its a pretty big amount of work doing all the compiler/IDE plugin/cache/reloading stuff - so getting (1) and (2) done first makes life much simpler (IDEA FTW!).

If I understand your approach correctly, you’ve kinda gone for an external DSL which is kinda like (2) and (3) combined. Though if you’re going to go to all the effort of having a separate kind of file thats not a regular Kotlin file, having to wire in IDEA support to be able to edit it & have a compile step and so forth you may as well go the whole hog and do a real external DSL (Razor/Play and Jade are my favourite).

I’m wondering if your approach of a new file format is worth all the effort? e.g. what about just using real Kotlin files (since really if you strip the \<html\> tags thats what you have). Then we’re using (2) - real kotlin files that IDEA edits and if we can use @Language(“HTML”) on a base trait we can get HTML language injection for free (when [KT-2428](http://youtrack.jetbrains.com/issue/KT-2428) is fixed). e.g. this example: [https://github.com/parroit/kweb/blob/master/sites/welcome/src/main/resources/views/layout.html.kt](https://github.com/parroit/kweb/blob/master/sites/welcome/src/main/resources/views/layout.html.kt) could be implemented something like this - not needing an external DSL at all & having immediate IDEA/maven/ant. support…

```kotlin
package templates

```

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [July 19, 2012, 10:52am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/25 "2012-07-19T10:52:33Z")

</div>

What I'm trying to do is really only 2), without any DSL option. I did the external compilation just as a workaround for the fact that we cannot inject html -\> kotlin right now,but instead we can inject kotlin-\>html. Only that html it's obviously not directly compilable by Kotlin compiler!

But I agreed with you, it’s better to wait for the language injection to work in the correct way, and things will get far easier than they are now.

So, I’m porting the file you linked to kool template (also because of [this other Kotlin bug](https://github.com/parroit/kweb/issues/1#issuecomment-7062185), that make impossible to compile the view via mvn)

I would prefer to have both 1) and 2) option in my ideal framework.  
My personal preferred choice is for a template system like 1), but I think many people (web designer) instead will feel more confortable with a  
plain html syntax like 2)

Regarding your purposed syntax , I don’t fully understand the need of&nbsp;&nbsp;a separate trait.  
It’s not more concise if we directly decorate the fun in the main view class?

```kotlin

package templates
import kw.views.*
import sites.welcome.*
class MyTemplate(val someParams: Foo) : HtmlTemplate {
  Language(“HTML”) fun render() = “”"
…
${someParams.something}
…
“”"
}

```

or, without class at all:

```kotlin

package templates
import kw.views.*
import sites.welcome.*
Language(“HTML”)
fun MyTemplate(someParams: Foo) = HtmlTemplate {“”"
…
${someParams.something}
…
“”"
}

```

---

<div class="post-metadata">

**Author:** ![jstrachan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstrachan/32/1559_2.png) [@jstrachan](https://discuss.kotlinlang.org/u/jstrachan)\
**Post date:** [July 19, 2012, 1:40pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/26 "2012-07-19T13:40:18Z")

</div>

Yeah, a function works too; I just used a class as it avoids having to remember to add the @Language annotation

---

<div class="post-metadata">

**Author:** ![parroit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/parroit/32/1560_2.png) [@parroit](https://discuss.kotlinlang.org/u/parroit)\
**Post date:** [July 19, 2012, 2:04pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/27 "2012-07-19T14:04:39Z")

</div>

Ah ok i get it now. Yes, could be useful. But I think that we can then directly decorate the HtmlTemplate function (I'm not sure if caould be done this way).

```kotlin

fun MyTemplate(someParams: Foo) = HtmlTemplate {"""
…
${someParams.something}
…

```

---

<div class="post-metadata">

**Author:** ![jstrachan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstrachan/32/1559_2.png) [@jstrachan](https://discuss.kotlinlang.org/u/jstrachan)\
**Post date:** [July 19, 2012, 2:08pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/28 "2012-07-19T14:08:00Z")

</div>

Though I wonder if the function which returns the String would still need to be annotated with @Language("HTML") to ensure the language injection works?

---

<div class="post-metadata">

**Author:** ![NSkvortsov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nskvortsov/32/1538_2.png) [@NSkvortsov](https://discuss.kotlinlang.org/u/NSkvortsov)\
**Post date:** [May 5, 2014, 12:53pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/29 "2014-05-05T12:53:54Z")

</div>

Just whanted to check if anyone is still working on Kotlin-Vert.x integration.

Most of the links from this thread are pointing to projects with no recent activity. Are there some non-obvious obstacles in the integration? Any tooling related problems?

---

<div class="post-metadata">

**Author:** ![ikant](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ikant/32/1524_2.png) [@ikant](https://discuss.kotlinlang.org/u/ikant)\
**Post date:** [May 14, 2014, 5:15pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/30 "2014-05-14T17:15:10Z")

</div>

Creating a language integration with Vert.x is a non-trivial exercise that requires on the fly compilation and byte code injection if memory serves.&nbsp;&nbsp;Setting up the test suite is likewise a bit of a bear.&nbsp;&nbsp;I've tried a few times to get it working with some success but never went all the way for various reasons.&nbsp;&nbsp;Mostly time.

Now there is talk about Vert.x 3.0 as a complete re-write.&nbsp;&nbsp;So I would suggest if an effort is going to be made to integrate Kotlin to wait for 3.0.&nbsp;&nbsp;Here is the latest:

[https://groups.google.com/forum/](https://groups.google.com/forum/)#!searchin/vertx/3.0|sort:relevance|spell:true/vertx/DHL9cAg4SYo/FAqi1iBimOwJ

[https://github.com/eclipse/vert.x/wiki/Vert.x-3.0-plan](https://github.com/eclipse/vert.x/wiki/Vert.x-3.0-plan)

---

<div class="post-metadata">

**Author:** ![ikant](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ikant/32/1524_2.png) [@ikant](https://discuss.kotlinlang.org/u/ikant)\
**Post date:** [May 21, 2014, 9:18pm UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/31 "2014-05-21T21:18:01Z")

</div>

Hi Nikita!

The work on vertx 3.0 has begun.&nbsp;&nbsp;I will likely give a stab at Kotlin integration.&nbsp;&nbsp;I’ll publish anything I do on github if you’d like.

-Steve

---

<div class="post-metadata">

**Author:** ![napperley](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@napperley](https://discuss.kotlinlang.org/u/napperley)\
**Post date:** [February 13, 2017, 5:38am UTC](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580/32 "2017-02-13T05:38:21Z")

</div>

By the way Vert.x will introduce Kotlin support in v3.4.0. Currently Vert.x 3.4.0 is in beta with the [first release already out](http://vertx.io/blog/vert-x-3-4-0-beta1-release/).

[Previous page](https://discuss.kotlinlang.org/t/kotlin-and-vert-x/580.md?page=1)
