将 Scala 融入到现有的 Java EE 项目中?

发布于 2024-12-02 00:18:49 字数 1006 浏览 0 评论 0原文

我有很多关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2024-12-09 00:18:49

你问了很多问题。我将尝试一次一一地解决所有这些问题。

问题:

scala.exe 的真正用途是什么?有人可以概括一下什么吗
scala.exe 与 java.exe 有何不同?是否存在运行时黑魔法
在 scala.exe 中除了提供解释器 shell 之外?

scala.bat 可以根据参数执行多种操作:

  • 它可以启动解释器 shell
  • 它可以执行 Scala 脚本文件
  • 它可以从类路径执行已编译的 Scala 二进制文件
  • 它可以执行 jar 文件

当启动二进制文件时,scala.bat 将简单地 执行调用 java.exe,并将 scala-library.jar 添加到类路径中。没有任何魔法。

问题:

如果我启动了 scala 代码,我可以链接到现有的 java 程序吗?
使用 java.exe 进行处理?如果是这样,我的 CLASSPATH 是否需要更改为链接
在scala标准库jar中?另外,如果我启动
java.exe,在 scala 中链接是否需要任何新的 -javaagent 参数
代码?

所有 Scala 二进制文件都是简单的 jar。唯一的区别是它们需要 scala 运行时库 (scala-library.jar)。因此,当使用 java.exe 启动时,您只需按照启动具有依赖项的 jar 时的步骤即可。再说一次,没有魔法,也没有额外的开关。

问题:

有没有办法在我现有的网络中将 scala 代码包含在 jar 中
应用程序 .war 文件(或 WEB-INF/classes 中)并让它运行?

Scala jar 就像 java jar 一样,因此您可以这样对待它们。

问题:

最后,将新的 Scala 代码合并到现有的 Spring 中
框架 + JSF2 Web 应用程序,就像尝试将圆钉装入
方孔?我看到一长串为 Scala 设计的 Web 框架
可用,但我想知道 Scala 有多流畅或多尴尬
会使用像 JSF2 这样的商品工具。这些是基于 Scala 的吗?
Web 框架是非 Java 开发人员迁移到
Scala 社区并希望在
斯卡拉语言?或者,JSF2 的方式有什么内在的东西吗?
设计的目的是,一旦我成为 Scala 专家,我就会发现它
试图将两者混合在一起,结果一团糟,我浪费了时间?

使用 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文