简体   繁体   English

将rails移植到java

[英]Porting rails to java

I have a ruby on rails application and thinking about porting it to java. 我在rails应用程序上有一个ruby,并考虑将其移植到java。 What are the things I should consider before that? 在此之前我应该​​考虑哪些事情? How hard is that task in terms of changes required? 在所需的变更方面,这项任务有多难?

Any advice from the people who have walked this path is greatly appreciated. 非常感谢来自走这条道路的人们的任何建议。

Motivation: I have two web applications using same data. 动机:我有两个使用相同数据的Web应用程序。 One is in java, another - rails. 一个是java,另一个是rails。 As a result, they both have databases and lots of stuff is sent back and forth and stored in copied tables. 结果,他们都有数据库,许多东西来回发送并存储在复制的表中。 As an addition it is extremly slow. 作为补充,它极其缓慢。 I can't move java to RoR, so thinking about what it'll take to move RoR to java (jvm that is). 我不能将java移动到RoR,所以考虑将RoR移动到java(jvm)需要什么。

If I were in your position, I would try running your Ruby code in JRuby which is an implementation of Ruby that runs on the JVM. 如果我在你的位置,我会尝试在JRuby中运行你的Ruby代码,这是在JVM上运行的Ruby实现。 It supports rails , which means you should be able to take your code and run it on the JVM. 它支持rails ,这意味着您应该能够获取代码并在JVM上运行它。

Once that's done, you can start writing new features in java, and it should work with your old code transparently. 完成后,您可以开始在java中编写新功能,它应该透明地使用您的旧代码。 You can also begin the task of rewriting some of your code in Java, without breaking comparability. 您还可以开始用Java重写一些代码的任务,而不会破坏可比性。

What's the motivation for porting this ? 移植这个的动机是什么?

If you need to integrate with Java libraries, there are numerous options available other than porting the whole app to Java. 如果需要与Java库集成,除了将整个应用程序移植到Java之外,还有许多其他选项可供选择。

If you need a direct port, then (as Chad has illustrated) JRuby may be the way to go. 如果你需要一个直接端口,那么(正如Chad所说) JRuby可能就是这样。

If you want to do a complete rewrite, but keep the RoR paradigm, check out Grails , which is a JVM-based RoR equivalent using Groovy (a Java Virtual Machine-compatible language that allows you to bind in Java libraries) 如果你想完全重写,但保留RoR范例,请查看Grails ,这是一个基于JVM的RoR等效使用Groovy (一种允许你在Java库中绑定的Java虚拟机兼容语言)

In general switching out a core component or framework means that you will essentially have to reimplement some or even lots of your application. 通常,切换核心组件或框架意味着您将基本上必须重新实现一些甚至许多应用程序。 Hence, you usually want a good reason to do so. 因此,您通常希望有充分的理由这样做。

If I understand your question correctly you need to deploy on a platform without Ruby but with a JVM. 如果我正确理解您的问题,您需要在没有Ruby但使用JVM的平台上进行部署。 In that case I would make it run with JRuby as the very first priority as this is with a very high probability the approach needing the least amount of work. 在这种情况下,我会让它以JRuby作为第一优先级运行,因为这种方法很可能需要最少量的工作。

This may seem like an obvious solution, but have you tried running both applications with the same database? 这似乎是一个明显的解决方案,但您是否尝试使用相同的数据库运行这两个应用程序? My company is currently migrating our software from PHP to Rails, and while we're re-coding components one-by-one, we let both applications use the same database. 我的公司目前正在将我们的软件从PHP迁移到Rails,虽然我们逐个对组件进行重新编码,但我们让这两个应用程序使用相同的数据库。 No need to send data back and forth, as long as you make sure the applications don't conflict. 只要确保应用程序不冲突,就不需要来回发送数据。

Check out playframework.org - it's a sweet web framework completely written in Java and the best Rails rip-off in Java I've seen to date. 查看playframework.org - 这是一个完全用Java编写的甜蜜的Web框架,以及迄今为止我见过的最好的Java Rails-off。 I ported a fairly simple app over to the Playframework in a few days. 几天后,我将一个相当简单的应用程序移植到Playframework上。 In some ways it's sweeter than Rails because of the way it uses Annotations to mix in code in a type safe manner. 在某些方面,它比Rails更甜,因为它使用Annotations以类型安全的方式混合代码。 If you're a rails programmer with a Java background, you'll be productive almost instantly because the framework maps directly to the Rails world. 如果您是具有Java背景的rails程序员,那么几乎可以立即提高效率,因为该框架直接映射到Rails世界。

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

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