How do I use Kotlin with Google App Engine?

I've been trying to set up a Google App Engine with IDEA (I'm an IDEA newbie, but I've got a decade of experience with Eclipse).

With signfiicant help from Jetbrains support, I’ve now got a test GAE project set up, and I can run it and see the output of a simple servlet in my web browser.

So I deleted this simple servlet and created a Kotlin file containing a class with the same name in the same package, also subclassing HttpServlet, with a doGet() method.  I added the kotlin-runtime.jar to the WEB-INF/lib folder, which is where libraries are supposed to go in Google App Engine.

Unfortunately, when I try to run this now I get a ClassNotFoundException - it can’t find the Kotlin class with the servlet.

What am I doing wrong?


I have no experience with GAE, but I'd do following:

  1. Use java

  2. Get any external java library (like commons-lang)

  3. Place library in WEB-INF/lib

  4. Write simple servlet that calls any method of that library in doGet()

If all this does not work, then problem is not in Kotlin. If it works, then probably something’s wrong with Kotlin, we need to think.

I wrote a Java servlet that accessed the AbstractIterator class in the kotlin-runtime.jar library, and it worked fine.  It seems that the issue is that the Kotlin class isn't being compiled, or the resultant .class files are not being put in the same place as the Java files.

Please share the project somewhere: all sources, all binaries (including you've compiled) and show full stack trace of error. Maybe I could help you find, what's wrong.

Per your request I've attached the project, although note that it assumes that the Google App Engine SDK is here:


Here is the exception I get when I try to run it (note that it seems to work fine when I use a Java file that has the same class name, package, and functionality):

Apr 7, 2012 7:21:46 PM warn WARNING: EXCEPTION java.lang.ClassNotFoundException: testpack.TestServlet at$ at Method) at at java.lang.ClassLoader.loadClass( at at java.lang.ClassLoader.loadClass( at org.mortbay.util.Loader.loadClass( at org.mortbay.util.Loader.loadClass( at org.mortbay.jetty.servlet.Holder.doStart( at org.mortbay.jetty.servlet.ServletHolder.doStart( at org.mortbay.component.AbstractLifeCycle.start( at org.mortbay.jetty.servlet.ServletHandler.initialize( at org.mortbay.jetty.servlet.Context.startContext( at org.mortbay.jetty.webapp.WebAppContext.startContext( at org.mortbay.jetty.handler.ContextHandler.doStart( at org.mortbay.jetty.webapp.WebAppContext.doStart( at org.mortbay.component.AbstractLifeCycle.start( at org.mortbay.jetty.handler.HandlerWrapper.doStart( at org.mortbay.component.AbstractLifeCycle.start( at org.mortbay.jetty.handler.HandlerWrapper.doStart( at org.mortbay.jetty.Server.doStart( at org.mortbay.component.AbstractLifeCycle.start( at at at at$StartAction.apply( at$ParseResult.applyArgs( at<init>( at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at com.intellij.rt.execution.application.AppMain.main(

[|attachment](upload:// (6.15 MB)

According to stack trace problem is not with kotlin runtime, app engine cannot find testpack.TestServlet.

How do you start your application?

If you just execute something like

…/appengine-java-sdk- web

it should not work, because app engine looks for classes in web/WEB-INF/lib and web/WEB-INF/classes and testpack.TestServlet is not in these folders.

I did

cp -r out/production/gaetest1 web/WEB-INF/classes

After that servlet works fine.

Yes, I can confirm that manually copying the class files across and running GAE from the command line as you suggest does work - yay progress! ;-)

But the question is: why isn’t this working from within IDEA - since it was working with Java?  To start it I was just hitting the green “Play” button in IDEA (“Run ‘AppEngine Dev’”).

This seems to work fine when the source file is Java, it copies the compiled class files over to WEB-INF/classes as it should (I think it is configured in Project Structure -> Artifacts), so why wouldn’t it be doing this for a Kotlin source file?

It seems to be a bug somewhere between IDEA's build/deploy infrastructure and Kotlin. Please, feel free to file an issue in our bug tracker. Thanks