开发者

Weaving Scala into existing Java EE projects?

I have many questions about scala. I have done a bit of reading and googling and SO'ing and not found any solid answers readily available. I'm not at the experimentation/prototyping stage yet, so I thought I might as well just ask my questions and get some expert knowledge for everyone to share. Thanks in advance!

What is scala.exe really for? Can someone give a rundown about what scala.exe does differently than java.exe? Is there runtime black magic in scala.exe other than providing for an interpreter shell?

(UPDATE: There is no such thing as a scala.exe. Scala ships with a simple batch script launcher, scala.bat (or scala on *nix). The Scala runtime is java.exe with Scala's standard library jars in the CLASSPATH.)

Can I link in scala code to an existing java program if I launched the process with java.exe? I开发者_运维问答f so, does my CLASSPATH need to change to link in the scala standard library jars? Also if I am launching with java.exe, are any new -javaagent parameters required to link in scala code? Is there a way to include scala code in jars in my existing web application .war file (or in WEB-INF/classes) and have it run?

Conversely, if scala.exe is required in my Java EE app server launcher to execute scala+java code, can scala.exe take all my esoteric -XX:InsertYourCrazySunPerfSwitchHere JVM command line parameters?

Finally, is incorporating new Scala code into an existing Spring Framework + JSF2 web application like trying to fit a round peg into a square hole? I see long lists of web frameworks designed for Scala that are available, but I wondered how smooth or how awkward Scala would be playing with commodity tools like JSF2. Are these Scala-based web frameworks the byproduct of non-Java developers migrating to the Scala community and wanting to recreate their framework du jour in the Scala language? Or, is there something intrinsic about the way JSF2 is designed such that, once I became an expert at Scala, I would see it's a sloppy mess trying to mix the two and I had wasted my time?


You have asked many questions. I will try to address them all, one at a time.

Question:

What is scala.exe really for? Can someone give a rundown about what scala.exe does differently than java.exe? Is there runtime black magic in scala.exe other than providing for an interpreter shell?

scala.bat can do several things depending on the arguments:

  • it can launch an interpreter shell
  • it can execute a Scala script file
  • it can execute a compiled Scala binary from a classpath
  • it can execute a jar file

When launching binaries, scala.bat will simply call java.exe with scala-library.jar added to the classpath. There is no magic of any kind.

Question:

Can I link in scala code to an existing java program if I launched the process with java.exe? If so, does my CLASSPATH need to change to link in the scala standard library jars? Also if I am launching with java.exe, are any new -javaagent parameters required to link in scala code?

All the Scala binaries are simple jars. The only difference is that they require the scala runtime library (scala-library.jar). So when launching with java.exe you simply follow the steps you would when launching a jar with dependencies. Again, there is no magic and no extra switches.

Question:

Is there a way to include scala code in jars in my existing web application .war file (or in WEB-INF/classes) and have it run?

Scala jars are just like java jars, so you can treat them as such.

Question:

Finally, is incorporating new Scala code into an existing Spring Framework + JSF2 web application like trying to fit a round peg into a square hole? I see long lists of web frameworks designed for Scala that are available, but I wondered how smooth or how awkward Scala would be playing with commodity tools like JSF2. Are these Scala-based web frameworks the byproduct of non-Java developers migrating to the Scala community and wanting to recreate their framework du jour in the Scala language? Or, is there something intrinsic about the way JSF2 is designed such that, once I became an expert at Scala, I would see it's a sloppy mess trying to mix the two and I had wasted my time?

Using Java libraries from Scala is at least as easy as using them from Java and often much smoother. On the other hand Scala is much richer that Java. So you will feel that Java libraries are lacking as soon as you start getting used to Scala.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜