2 Replies Latest reply on Jan 21, 2010 10:22 PM by Greg Zoller

    Seam Project with Scala

    Greg Zoller Newbie

      Hello,


      I've seen a couple threads about the possibility of using Seam and Scala and understand it should be possible in principle.


      I'm interested if anyone has actually done it.  I'd like to take a project I created w/seamgen and while bit pieces of it will still be Java, I want to use some Scala classes as well.


      I'm using Eclipse (Galileo).  I've installed both the JBoss Tools for Seam as well as the latest Scala Eclipse plugin.  I can successfully work with a Seam project and a (separate) Scala project, but now I'm trying to blend Seam w/some Scala code.


      When I tried to add a trivial Scala class to my Seam project's source tree I got bizarre error messages, like it didn't know what to do with the Scala or couldn't find a library or something.  I then added the scala-library.jar file to the project's lib dir and build path.  No dice (same problem).  Error slice is below.




      scala.tools.nsc.MissingRequirementError: class scala.Array not found.
      at scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:514)
      at scala.tools.nsc.symtab.Definitions$definitions$.getClass(Definitions.scala:472)
      ...





      Anyone out there already climbed this mountain and know where to put all the magic files?


      Thanks!
      Greg

        • 1. Re: Seam Project with Scala
          Arbi Sookazian Master

          I don't have any hands-on experience (yet) with Scala but it sounds like you may be missing a Scala library in your classpath unless a Scala-Seam integration library is required?  I'm pretty sure Scala is like Groovy in that they just require a JVM to exec...  Is there a Groovy-Seam integration library, maybe you can check that first??

          • 2. Re: Seam Project with Scala
            Greg Zoller Newbie

            Ok... got it.  Here's the HOWTO in order to use Seam w/Scala.


            1)  Download/install the nightly Scala Eclipse plug-in.  This gives you Scala 2.8 (beta).  May work w/2.7.x but frankly the community buzz confirms the older Eclipse plugin is bumpy.  Take your best shot here.


            2)  Import a seam-gen'ed project like normal


            3)  In your Eclipse left-hand-side project view (Seam perspective), right click your project and go down to the Scala menu and select Add Scala Nature.


            4)  In your project's lib directory import the scala-library.jar (from the normal Scala distribution) for Scala 2.8 (or whatever, to match your Eclipse plugin's Scala version


            5)  Edit deployed-jars-ear.list and add scala-library.jar so that the library will deploy to your app server as part of the ear.


            You can now use Scala in your project with the normal Java/Scala limitations.  Here's a sample of a Seam component that injects a trivial Scala class (also a component):




            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.AutoCreate;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            
            @Name("message")
            @Scope(ScopeType.CONVERSATION)
            @AutoCreate
            public class Message {
            
                 @In(create=true)
                 MsgText msgText;  // Scala object injected
                 
                 public String getSay() { 
                      return "Hey! "+msgText.say();
                 }
            }



            and the Scala component:




            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            
            @Name("msgText")
            @Scope(ScopeType.CONVERSATION)
            class MsgText {
                 val msg = "Some message text"
                 def say() = { msg }
            }



            I'm sure there'll be a gotcha here or there, but this is a wonderful prospect for those, like me, who love the potential of Scala but want the features Seam provides.