简体   繁体   English

Rails和Jruby有什么关系?

[英]How do Rails and Jruby relate?

Background: I have a java library that is accessed by many developers - usually via java. 背景:我有一个Java库,许多开发人员都可以通过Java访问。 However, a few devs hope to access this via a Ruby API. 但是,一些开发人员希望通过Ruby API访问它。 I am gravitating in the direction of Jruby in order to implement a Java-Ruby API. 为了实现Java-Ruby API,我倾向于Jruby。

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; 我主要担心的是,这些开发人员将无法在其当前的Ruby on Rails开发框架中使用该API。 but instead will have to operate within Jruby's rails environment. 但必须在Jruby的Rails环境中运行。 Is this going to be the case? 是这样吗?

  2. Perhaps I'm missing a connection between Jruby and Ruby on Rails. 也许我错过了Jruby和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? 但是似乎您可以在Rails中工作,也可以在Jruby的Rails中工作-从技术上讲,这是两个不同的开发环境吗?

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. 编辑 :强制开发人员(实际上是更具体的客户)为了适应该API而对其项目进行较大的更改并不是真正的选择。 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)? 因此,如果必须在Rails应用程序上将其Rails应用程序转换为Jruby,那么也许有人可以为我提供另一种选择(Jruby除外)?

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. 根据您的应用程序,可能会根据该答案中指出的注意事项,无缝移植您的RoR应用程序以使其在JRuby上运行。 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. 或者,您可以考虑将这些Java库功能作为在JRuby上构建的内部Web服务(可能是Rails或Sinatra或类似)提供给MRI Rails应用程序。 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. 如果您以后对这种工作感到满意,那么可以考虑将它们折叠在一起,如果可以的话,将它们全部合并到JRuby-on-Rails下。

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. 由于我不熟悉您的应用程序或Java库的功能,因此这有点抽象,但是我相信您可以填写空白以满足您的需求。

It seems that full porting of your Rails apps to run on Jruby is not feasible. 将Rails应用程序完全移植到Jruby上似乎是不可行的。 Fine. 精细。 So one idea would be to expose your Java library as a web service (eg RESTful) to your RoR application. 因此,一个想法是将Java库作为Web服务(例如RESTful)公开到RoR应用程序。 Let's call this thing JLS. 我们称其为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). 在这种情况下,它可以作为Java或Jruby网络服务运行,侦听请求,调用库并发送回响应(在这里挥手示意,但您知道了)。

Depending on what your developers are more comfortable with you can create JLS in Java running a Servlet container maybe. 根据您的开发人员更满意的情况,您可以在Java中运行Servlet容器来创建JLS。 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. 或者,您可以在Ruby上开发JLS,并在Jruby上运行(绑定到Java库),然后使用Rails或Sinatra之类的框架来实现它。

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. 在RoR方面,假设您已使JLS成为RESTful(并且我不知道这是否适合您的情况),则可以使用ActiveResource工具与JLS进行通信。

In summary the RoR app and JLS run in separate memory spaces (maybe even different hosts). 总之,RoR应用程序和JLS在单独的内存空间(甚至可能是不同的主机)中运行。 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. 每个都可以在某种程度上独立开发(当然要使用RESTful接口协议),并且您的RoR应用程序无需中断或冒险。

This suggested option comes with tons of small print but I hope you get the general idea. 这个建议的选项带有大量的小字体,但我希望您能理解。

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. 首先,我应该提到Ruby on Rails只是Ruby代码,并且相同的代码可以在JRuby环境(在JVM上)或MRI(用C编写)运行时中运行。

However, only JRuby can load Java classes and use a Java API. 但是,只有JRuby可以加载Java类并使用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. 让您的客户将其部署环境切换到JRuby可能不可行,但是如果您可以用Java设置一个可以说XML或JSON的服务,那么他们将可以从Rails轻松使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM