将 Scala 融入到现有的 Java EE 项目中?
我有很多关于 scala 的问题。我已经做了一些阅读、谷歌搜索和搜索,但没有找到任何可靠的答案。我还没有处于实验/原型阶段,所以我想我不妨提出我的问题并获得一些专业知识供大家分享。提前致谢!
scala.exe 的真正用途是什么?有人可以概述一下 scala.exe 与 java.exe 的不同之处吗?除了提供解释器 shell 之外,scala.exe 中是否还有运行时黑魔法?
(更新:不存在 scala.exe 这样的东西。Scala 附带一个简单的批处理脚本启动器 scala.bat(或 *nix 上的 scala)。Scala 运行时是 java。 ?
如果我使用 java.exe 启动进程,我可以在 scala 代码中链接到现有的 java 程序吗 如果是这样,我的 CLASSPATH 是否需要更改为链接到 scala 标准库 jar 中?另外,如果我使用 java.exe 启动,是否需要任何新的 -javaagent 参数才能链接到 scala 代码?有没有办法将 scala 代码包含在我现有的 Web 应用程序 .war 文件(或 WEB-INF/classes)的 jar 中并让它运行?
相反,如果我的 Java EE 应用服务器启动器中需要 scala.exe 来执行 scala+java 代码,那么 scala.exe 是否可以获取我所有深奥的 -XX:InsertYourCrazySunPerfSwitchHere JVM 命令行参数?
最后,将新的 Scala 代码合并到现有的 Spring Framework + JSF2 Web 应用程序中是否就像尝试将圆钉装入方孔?我看到了一长串专为 Scala 设计的可用 Web 框架,但我想知道 Scala 与 JSF2 这样的商品工具一起使用时会有多流畅或多尴尬。这些基于 Scala 的 Web 框架是否是非 Java 开发人员迁移到 Scala 社区并希望用 Scala 语言重新创建他们的框架的副产品?或者,JSF2 的设计方式是否有一些内在的东西,一旦我成为 Scala 的专家,我就会发现尝试将两者混合起来是一种草率的混乱,而且我浪费了时间?
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? 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? 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你问了很多问题。我将尝试一次一一地解决所有这些问题。
问题:
scala.bat 可以根据参数执行多种操作:
当启动二进制文件时,scala.bat 将简单地 执行调用 java.exe,并将 scala-library.jar 添加到类路径中。没有任何魔法。
问题:
所有 Scala 二进制文件都是简单的 jar。唯一的区别是它们需要 scala 运行时库 (scala-library.jar)。因此,当使用 java.exe 启动时,您只需按照启动具有依赖项的 jar 时的步骤即可。再说一次,没有魔法,也没有额外的开关。
问题:
Scala jar 就像 java jar 一样,因此您可以这样对待它们。
问题:
使用 Scala 中的 Java 库至少与使用 Java 中的 Java 库一样简单,而且通常更加流畅。另一方面,Scala 比 Java 丰富得多。所以一开始习惯Scala你就会觉得缺少Java库。
You have asked many questions. I will try to address them all, one at a time.
Question:
scala.bat can do several things depending on the arguments:
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:
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:
Scala jars are just like java jars, so you can treat them as such.
Question:
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.