3

I try to deploy a simple application in Scala using akka on Tomcat 7.

In the first version, the actor system and the main actor were started directly from a Scala object.

In the second version, I created an initializer (extending ServletContextListener) in order to start the actor system and the actor at the deployment of the war.

In both case, I get a java.lang.LinkageError like the following :

java.lang.LinkageError: loader constraint violation: when resolving method "akka.actor.Props$.apply(Lscala/reflect/ClassManifest;)Lakka/actor/Props;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, com/my-app/Transfert$, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, akka/actor/Props$, have different Class objects for the type scala/reflect/ClassManifest used in the signature
  com.my-app.Transfert$.<init>(Transfert.scala:14)
  com.my-app.Transfert$.<clinit>(Transfert.scala)
  com.my-app.Transfert.getState(Transfert.scala)
  org.apache.jsp.transfert_jsp._jspService(transfert_jsp.java:85)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I searched on Google and everywhere, but I didn't find a simple example of how to deploy a Scala/akka application on Tomcat 7 ?

I know there was an akka.http package in akka 1.3, but I want to use akka 2.0 (at least). It seems akka.http has disappeared in favor of the use of play-mini. But I would prefer not to use play-mini or play.

Is there any advice ? Any reading suggestion ? Or ??

Taggiasco
  • 85
  • 1
  • 5

1 Answers1

0

We have Akka actors 2.1 running inside Jetty 8 - it should not be too different.

You seem to be facing ClassLoader issues (I assume you are using java 6 and do not have binary compatibilities issues).

May I suggest you try to remove scala-library.2.10.0.jar and akka-actor_2.10-2.1.0.jar from your war and drop them in the tomcat 7 lib folder ?

Bruno Grieder
  • 28,128
  • 8
  • 69
  • 101
  • In fact, they are not in the war. akka-actor-2.0.jar and scala-library-2.9.2.jar are in the lib folder of Tomcat. – Taggiasco Feb 13 '13 at 16:34
  • Should I try to update to the latest version of Scala and Akka ? But as it seems to be a `ClassLoader` problem, that should not solve it. – Taggiasco Feb 14 '13 at 06:08
  • Things you *could* try: upgrade to 2.10 (`ClassManifest` is deprecated), move all scala jars in your webapp/lib and remove them from tomcat/lib (hoping all classes will be loaded from the `WebappClassLoader`), force the classLoader on your `Thread.currentThread` using `setContextClassLoader` in order to load from the `StandardClassLoader`. If you find a solution, please tell us. – Bruno Grieder Feb 14 '13 at 08:09
  • I will upgrade to 2.10 as soon as I can. However I don't understand how I'm supposed to use `Thread.currentThread` or `setContextClassLoader`. Well, something like `Thread.currentThread.setContextClassLoader( ... )` but with what parameter ? – Taggiasco Feb 14 '13 at 11:03
  • For the moment, I'm a bit blocked with the upgrade, since config library does not seem to be the good one (http://stackoverflow.com/questions/14893109/akka-and-typesafe-config-versions-issue). I'll tell you as soon as I get something new. – Taggiasco Feb 15 '13 at 11:36
  • It seems it works now, because I can deploy the application and run it. But not from a `ServletContextListener` but it doesn't matter! Thank you! – Taggiasco Feb 15 '13 at 12:25