Very simple Jersey app works

The maven plugin doesn't assemble the war file quite right, but I found this simple Jersey app produces the correct result when I query it:

https://ae6rt@github.com/ae6rt/jersey-kotlin.git

However, I had to manually copy the intellij-core and kotlin-runtime jars to the exploded war archive’s WEB-INF/lib directory.  The standard maven war packaging for some reason does not produce the correct .war file.

So the WEB-INF/lib directory for the case where the jar set is correct looks like:

``

$ find webapps/ws/WEB-INF/lib
webapps/ws/WEB-INF/lib
webapps/ws/WEB-INF/lib/asm-3.1.jar
webapps/ws/WEB-INF/lib/intellij-core.jar
webapps/ws/WEB-INF/lib/jersey-core-1.9.1.jar
webapps/ws/WEB-INF/lib/jersey-server-1.9.1.jar
webapps/ws/WEB-INF/lib/kotlin-runtime.jar


and the simple Jersey resource looks like:

``

import javax.ws.rs.Path
import javax.ws.rs.GET

Path(“/hello”)
class HelloResource() {

  GET
  fun getHello() : String {
  return “hello”
  }
}

whereupon

``

$ curl -i http://localhost:8080/ws/hello; echo
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/plain
Transfer-Encoding: chunked
Date: Sat, 17 Mar 2012 23:04:12 GMT

hello


The maven plugin prepares this set of libs in WEB-INF/lib, which does not work:

``

$ jar tf target/jersey-kotlin-1.0-SNAPSHOT.war  |grep WEB-INF/lib
WEB-INF/lib/
WEB-INF/lib/bt343-latest.lastSuccessful-core/
WEB-INF/lib/asm-3.1.jar
WEB-INF/lib/bt343-latest.lastSuccessful-core/intellij-core.@{extension}@
WEB-INF/lib/bt344-latest.lastSuccessful-kotlin-runtime.@{extension}@
WEB-INF/lib/jersey-core-1.9.1.jar
WEB-INF/lib/jersey-server-1.9.1.jar

which gives rise to this output from Tomcat

``

root cause
java.lang.ClassNotFoundException: jet.JetObject
     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
     java.lang.ClassLoader.defineClass1(Native Method)
     java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
     java.lang.ClassLoader.defineClass(ClassLoader.java:615)
     java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
     org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2823)
     org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1655)
     org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
     java.lang.Class.forName0(Native Method)
     java.lang.Class.forName(Class.java:247)

I pushed this a little further, adding an annotated function parameter

import javax.ws.rs.GET import javax.ws.rs.Path import javax.ws.rs.QueryParam

Path(“/hello”)
class HelloResource() {

  GET
  fun getHello( QueryParam(“name”) qs : String) : String {
  return "hello, " + qs
  }
}

and encountered this in the IDE when trying to use an annotated method / function parameter, with attached screenshot:

[INFO] --- kotlin-maven-plugin:0.2.3.8-beta-10:compile (compile-kotlin-sources) @ jersey-kotlin --- :: loading settings :: url = jar:file:/Users/petrovic/.m2/repository/com/goldin/plugins/kotlin-maven-plugin/0.2.3.8-beta-10/kotlin-maven-plugin-0.2.3.8-beta-10.jar!/ivyconf.xml [INFO] Compiling [/Users/petrovic/Projects/jersey-kotlin/src/main/kotlin] => [/Users/petrovic/Projects/jersey-kotlin/target/classes] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.254s [INFO] Finished at: Sat Mar 17 19:38:24 PDT 2012 [INFO] Final Memory: 37M/81M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-10:compile (compile-kotlin-sources) on project jersey-kotlin: Execution compile-kotlin-sources of goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-10:compile failed: [/Users/petrovic/Projects/jersey-kotlin/src/main/kotlin] compilation failed: Internal error: (12,28) java.lang.NullPointerException [ERROR] @IntrinsicMethods.java:248 [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException



[qp.png|attachment](upload://2Nia821dwU16SMxJz1aqFwBcBCX.png) (45.7 KB)

Looks like our parser is not ready for bare annotations on parameters, please surround them with []:

``

    GET
  fun getHello( [QueryParam(“name”)] qs : String) : String {
  return "hello, " + qs
  }

This produces what appears to be the same failure:

``

[INFO] — kotlin-maven-plugin:0.2.3.8-beta-10:compile (compile-kotlin-sources) @ jersey-kotlin —
:: loading settings :: url = jar:file:/Users/petrovic/.m2/repository/com/goldin/plugins/kotlin-maven-plugin/0.2.3.8-beta-10/kotlin-maven-plugin-0.2.3.8-beta-10.jar!/ivyconf.xml
[INFO] Compiling [/Users/petrovic/Projects/jersey-kotlin/src/main/kotlin] => [/Users/petrovic/Projects/jersey-kotlin/target/classes]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.618s
[INFO] Finished at: Sun Mar 18 05:53:34 PDT 2012
[INFO] Final Memory: 37M/87M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-10:compile (compile-kotlin-sources) on project jersey-kotlin: Execution compile-kotlin-sources of goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-10:compile failed: [/Users/petrovic/Projects/jersey-kotlin/src/main/kotlin] compilation failed: Internal error: (13,28) java.lang.NullPointerException
[ERROR] @IntrinsicMethods.java:248
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

The source code is here if it helps:

https://ae6rt@github.com/ae6rt/jersey-kotlin.git

which I build using

$ mvn clean package

I filed an issue to help track:

http://youtrack.jetbrains.com/issue/KT-1605