Rails 和 Jruby 有何关系?

发布于 2024-09-11 16:31:21 字数 559 浏览 11 评论 0原文

背景: 我有一个由许多开发人员访问的 java 库 - 通常通过 java 访问。然而,一些开发人员希望通过 Ruby API 访问它。为了实现 Java-Ruby API,我倾向于 Jruby 的方向。

问题:

  1. 我主要担心的是,这些开发人员将无法在他们当前的 Ruby on Rails 开发框架中使用 API;但必须在 Jruby 的 Rails 环境中运行。情况会是这样吗?

  2. 也许我缺少 Jruby 和 Ruby on Rails 之间的连接。但似乎您既可以在 Rails 中工作,也可以在 Jruby 的 Rails 中工作——这在技术上是两种不同的开发环境吗?

我真的很感激有人能对此做出任何说明。

编辑:强迫开发人员(实际上是客户更具体)对其项目进行重大更改以适应此 API 并不是真正的问题选项。那么,如果他们的 Rails 应用程序必须转换为 Jruby on Rails 应用程序,那么也许有人可以为我提供另一种选择(除了 Jruby)?

Background: I have a java library that is accessed by many developers - usually via java. However, a few devs hope to access this via a Ruby API. I am gravitating in the direction of Jruby in order to implement a Java-Ruby API.

Questions:

  1. My main concern is that these developers will not be able to utilize the API in their current, Ruby on Rails development framework; but instead will have to operate within Jruby's rails environment. Is this going to be the case?

  2. Perhaps I'm missing a connection between Jruby and Ruby on Rails. But it seems that you can either work in Rails, or work in Jruby's rails - are these technically two different development environments?

I would really appreciate any light someone could shed on this..

Edit: Forcing developers (actually clients to be more specific) to make large changes to their projects in order to accomodate for this API is not really an option. So, if their Rails apps would have to be converted to Jruby on Rails apps, then perhaps someone could offer yet another alternative for me (other than Jruby)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

逆光飞翔i 2024-09-18 16:31:21

首先,我应该提到,Ruby on Rails 只是 Ruby 代码,相同的代码可以在 JRuby 环境(在 JVM 上)或 MRI(用 C 编写)运行时运行。

但是,只有 JRuby 可以加载 Java 类并使用 Java API。要求您的客户将其部署环境切换到 JRuby 可能不可行,但如果您可以在 Java 中设置使用 XML 或 JSON 的服务,那么他们将能够轻松地从 Rails 使用它。

First, I should mention that Ruby on Rails is simply Ruby code, and the same code can run in the JRuby environment (on the JVM) or the MRI (written in C) runtime.

However, only JRuby can load Java classes and use a Java API. Asking your clients to switch their deployment environment to JRuby may not be feasible, but if you can set up a service in Java that speaks XML or JSON then they will be able to easily use it from Rails.

白鸥掠海 2024-09-18 16:31:21

您可能会找到类似的问题有帮助。根据您的应用程序,可能可以无缝移植您的 RoR 应用程序以在 JRuby 上运行,但须遵守该答案中指出的注意事项。但您需要确保这样做的好处能够平衡工作量和潜在风险。

或者,您可以考虑将这些 Java 库设施作为基于 JRuby 构建的内部 Web 服务(可以是 Rails 或 Sinatra 或类似服务)供您的 MRI Rails 应用程序使用。这样您就可以解耦各个元素并降低项目风险。如果您随后对这种工作感到满意,那么您可能会考虑将它们重新折叠在一起,所有这些都在 JRuby-on-Rails 下(如果有意义的话)。

更新:根据提问者的要求添加更多详细信息,

因为我不熟悉您的应用程序或 Java 库的功能,所以这会有些抽象,但我相信您可以填写空白以满足您的需求。

似乎将 Rails 应用程序完全移植到 Jruby 上运行是不可行的。美好的。因此,一种想法是将 Java 库作为 Web 服务(例如 RESTful)公开给您的 RoR 应用程序。我们称这个东西为JLS。在这种情况下,它将作为 Java 或 Jruby 网络服务运行,侦听请求、调用库并发回响应(这里一般是挥手,但您明白了)。

根据您的开发人员更熟悉的内容,您可能可以在运行 Servlet 容器的 Java 中创建 JLS。或者,您可以使用 Ruby 开发 JLS,在 Jruby 上运行(绑定到您的 Java 库)并使用 Rails 或 Sinatra 等框架来实现它。

在 RoR 方面,假设您已将 JLS 设为 RESTful(我不知道这是否适合您的情况),您可以使用 ActiveResource 工具与 JLS 进行通信。

总之,RoR 应用程序和 JLS 在不同的内存空间(甚至可能不同的主机)中运行。每个都可以在某种程度上独立开发(当然使用 RESTful 接口协议),并且您的 RoR 应用程序不需要被中断或面临风险。

这个建议的选项带有大量的小字,但我希望您能了解总体思路。

You might find the answers to a similar question helpful. Depending on your application it may be possible to seamlessly port your RoR app to run on JRuby subject to the caveats noted in that answer. But you'd want to be sure that the benefits of doing so balanced the effort and potential risks.

Alternatively you might consider making these Java library facilities available to your MRI Rails app as an internal web service (which could be Rails or Sinatra or similar) built on JRuby. That's way you would decouple the elements and de-risk the project. If you subsequently were comfortable with that working you might then consider collapsing them back together, all under JRuby-on-Rails if that made sense.

UPDATE: Adding more detail at questioners request

As I'm not familiar with what your application or Java libraries do this will be somewhat abstract but I trust you can fill in the blanks to suit your needs.

It seems that full porting of your Rails apps to run on Jruby is not feasible. Fine. So one idea would be to expose your Java library as a web service (e.g. RESTful) to your RoR application. Let's call this thing JLS. In this case it would run as a Java or Jruby network service, listening for requests, call into the library and send back responses (general waving of hands here but you get the idea).

Depending on what your developers are more comfortable with you can create JLS in Java running a Servlet container maybe. Or you could develop JLS in Ruby, running on Jruby (binding to your Java library) and use a framework like Rails or Sinatra to implement it.

On the RoR side, assuming you've made JLS RESTful (and I don't know if that's even appropriate in your case), you can use the ActiveResource facility for communicating with JLS.

In summary the RoR app and JLS run in separate memory spaces (maybe even different hosts). Each can be developed somewhat independently (with RESTful interface agreement of course) and your RoR app does not need to be disrupted or put at risk.

This suggested option comes with tons of small print but I hope you get the general idea.

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