File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ruby and the fly likes I don't know Ruby on Rails: can RoR and Java be in the same app? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "I don Watch "I don New topic
Author

I don't know Ruby on Rails: can RoR and Java be in the same app?

Rogerio Kioshi
Ranch Hand

Joined: Apr 12, 2005
Posts: 689
Hi,

I only work with Java, but I've been seen many people talking about Ruby on Rails. So, it must be the language of the future!
If I have an application written in Java, can it use RoR programming resources, and vice-versa?

Thanks


SCEA 5 (part 1), SCBCD, SCWCD, SCJP, CLP, CLS
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Rogerio Kioshi:
If I have an application written in Java, can it use RoR programming resources, and vice-versa?

That depends on what you mean by "programming resource"?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Hello Rogerio,

Actually, java and ruby appeared in the same year (1995), but ruby started gaining popularity nowadays. Sun did a clever move by adding a scripting API to java 6, so starting of java 6, you can use scripting languages within java.

As you know, each interpreted scripting languages has an interpreter engine, and as for ruby, there is a java implementation for the ruby engine written in java that has been around since 2001, and it's called JRuby.

So if you want to know whether you can run scrips written in ruby in a java application, I believe that the answer is yes. You can use JRuby to interpret and run those scripts, using of the new scripting API, which is available starting from java 6, or using the Apache Bean Scripting framework.

I would like to highlight that I'm not an expert, so I might be wrong somewhere, but overall, I think that my reply is quiet accurate.
[ February 06, 2008: Message edited by: Alaa Nassef ]

Visit my blog: http://jnassef.blogspot.com/
Jason Mayer
Ranch Hand

Joined: Oct 16, 2007
Posts: 31
ruby is a scripting language. rails is a framework for web development. getting ruby on rails to work with your java code depends on how you've set it up. you can use jruby as an intermediate step as Alaa Nassef mentions, but I think that you'll find using a pure ruby solution to be more elegant. java has come a long way and is certainly more agile than it used to be (pre java 5/6), but I still find that writing code in ruby takes less time and is certainly easier to configure (there aren't 5 bajillion xml files to set up like in java for instance).
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Well, I agree that the gazillion (not bajillion ) XML files are a pain, but with the introduction of annotations, and with the major open source players like spring, hibernate and EJB3 adopting it, the XML is reduced A LOT.

Note:
Something funny just struck me. Firefox's built in spell checker accepted "gazillion" but not "bajillion" .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61770
    
  67

Originally posted by Jason Mayer:
(there aren't 5 bajillion xml files to set up like in java for instance).

XML has little to do with Java per se. Yes, frameworks like Struts and Spring are heavily XML-based, but that doesn't really mean that to to use any Java that you need XML. To make such claims merely blows your credibility.

Now if you want to compare Rails to Struts, in this respect, that would be a valid comparison.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeff Ballie
Greenhorn

Joined: Jul 02, 2007
Posts: 12
I'm guessing that this question refers to the possibility of using Java code in a Ruby or Rails app? If so, it appears that you can create a class in Java and access it using Ruby/Rails - there's a tutorial on how to do this in netbeans at:

http://www.netbeans.org/kb/60/ruby/java-ruby.html

This does matter to me, because I use some third party software (ILOG Cplex) with a wonderful Java API, but I like Ruby and Rails, so the ability to call Java classes from ruby code in Rails would be useful.

Unfortunately, haven't tried it yet, so this is as far as I can go in this post... if anyone gives it a try, please let us know how it goes.
Matt Williams
Greenhorn

Joined: Feb 06, 2008
Posts: 14
Yes, it is definitely possible.

Here's links to examples:

Calling Java from JRuby
and
Java Integration

You'd be using JRuby and running in the JVM. I've been using rails within a JBoss instance for almost a year at this point....
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Originally posted by Bear Bibeault:
XML has little to do with Java per se.

I do agree with that, but any one who has to develop java applications will have to get stuck with XML configuration files. It doesn't matter what framework you use, usually you'll be faced with the ugly XMLs. ORM? Whether you use hibernate or iBATIS for your ORM, you'll be using XML for configuration & mappings (as I mentioned, annotations reduce the XML nowadays, but unfortunately they're not widely used).

Web? Well, you first have the deployment descriptor, then the config files for the framework you are going to use. It doesn't matter whether you use struts, strurs 2 (webwork), spring MVC, JSF, or even the unpopular tapestry 4, you'll be doing a lot of XML. You want to validate your data? Validation frameworks use XML. View technologies? Tiles, sitemesh, etc. all use XML configs.

Enterprise application? EJB & Spring use XML config. I know that now the allow annotations to remove the burden of XML, but still, XML is used a lot more than annotations till now. Even logging, you have frameworks like logback that have better features and performance than log4j use XML.

I agree that java as a language does not force you to use XML, but as a java developer, you'll find yourself forced to be using tons of XML files, unless of course you're developing desktop or mobile applications, but even this is not really guarantied.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I think Java developers should also have a look at Grails.
http://grails.codehaus.org/
Has anyone tried it out ?


Groovy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61770
    
  67

Originally posted by Alaa Nassef:

I do agree with that, but any one who has to develop java applications will have to get stuck with XML configuration files.

This is false.

You go on to list particular frameworks that use XML for configuration. It would be perfectly fair and correct to state that the use of these frameworks requires the use of XML. But to state that the use of Java requires XML is false.

XML is also used by non-Java frameworks.
Rogerio Kioshi
Ranch Hand

Joined: Apr 12, 2005
Posts: 689
Thanks people, you've clarified a lot.

My concern was that, if I have a Java application and RoR had easier ways to do some kind of new features on it, I could do this integration. Or maybe I have a RoR application and I wanted to make some Java code on it, for some kind of reason (familiarity with the language, for example).
[ February 07, 2008: Message edited by: Rogerio Kioshi ]
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
Originally posted by Rogerio Kioshi:
Hi,

I only work with Java, but I've been seen many people talking about Ruby on Rails. So, it must be the language of the future!
If I have an application written in Java, can it use RoR programming resources, and vice-versa?

Thanks


IMO, this is like pounding a square peg into a round hole.

Rails, and Ruby are infinitely more flexible then Java. If it is a web based app, and isn't too complicated, you could more then likely rewrite it in a fraction of the time the java app took


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Originally posted by Bear Bibeault:

This is false.

You go on to list particular frameworks that use XML for configuration. It would be perfectly fair and correct to state that the use of these frameworks requires the use of XML. But to state that the use of Java requires XML is false.

XML is also used by non-Java frameworks.

Hello Bear,

As I said before, I totally agree with you. My point is that for most java developers, developing web applications or enterprise applications will most probably put them in the situation where they will do a lot of XML configuration.

If Jason meant that java needs XML, then he's wrong, but I assume that what he meant was not clear enough in his post maybe that's because now I see that my post did not show what I meant correctly either).

Lot's of java and non java frameworks use XML configurations, and I believe that XML is cool, and it's great to be used for configurations, but I just hate that I need too much of it while using most frameworks.

I hope that we have reached a better understanding of what the other party meant. I'll now just go for some since it's 2 am already here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I don't know Ruby on Rails: can RoR and Java be in the same app?