JRuby 1.5 and Maven

Quick question: What’s the best/easiest way to use the latest 1.5
release to
compile a JRuby script to proper java bytecode in Maven (ant, rakefile,
plugin …)?
I’m sort of lost (ruby newbie).

Cheers,
stephanos

View this message in context:
http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28342154.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Stephanos,

Usually you’d just setup a ruby project (maybe using rails, sinatra, or
whatever if webapp), and then assuming you’re making a webapp, use
warble to package it up in a war.

In that war, it would have your jruby files (.rb files) and the jruby
jar, jruby-rack jar at least, and if you wanted (but don’t have to)
other jars in the WEB-INF/lib so that your JRuby code could call other
custom java classes. The gems, etc. all packaged up as .rb files as well
just like a ruby on rails, sinatra, etc. project. Warble puts all that
into the war. And Jruby is compiling ruby code at runtime. I probably
just butchered that description. I’d point you at the JRuby wiki at
Kenai but at the moment I just clicked on it, it is just sitting there,
so I assume it is down or being restarted:
http://kenai.com/projects/jruby/pages/Home

You can also call JRuby from other java code, etc. I’ve not done it, so
I can’t say much about it. See
http://en.wikipedia.org/wiki/JRuby#Calling_JRuby_from_Java

I came from a background of originally using Ant quite a bit (although
did some Maven 1 many years ago) and then was heavy into Maven 2 before
I got into JRuby/Ruby. So at first I also thought, “Can’t I just throw a
pom.xml together and build a JRuby project?” But, that isn’t the way you
probably want to go. You probably want to learn Ruby first. You might
even just try Ruby on Rails or a basic Ruby/Sinatra app first outside of
JRuby, and then after you do that, do the same in JRuby and use warbler
to deploy a war that you could host in Tomcat (for example). You don’t
have to start that way (I didn’t), but if I was to do it over again, I
might.

Note also that JRuby is not just about calling your custom Java classes
or reusing the myriad of Java libraries out there. Except for Ruby gems
that use C-extensions (which you used to be able to check at
http://isitjruby.com/ but at the moment it appears to be a default
“Joyent Accelerator” page), most of the gems, etc. available to Ruby can
be used in JRuby. I think it is easier to use Ruby from within JRuby
than calling/instantiating Java, even though it is plenty easy to use
Java from JRuby as well.

But I may be way off. What were you aiming to do?

Hope this helps,

Gary

On Apr 23, 2010, at 11:07 AM, stephanos wrote:

Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Gary, thank you for your reply :slight_smile:

The reason of my question is rather unusual. I run a website called
http://codingkata.org codingkata.org which provides programming
exercises
that are setup using Maven (so this is a must-requirement for me). I
write
the tasks in Java and the user can pick his favorite language for the
solution part.

So far I got almost all major JVM-based language supported, but not
JRuby
yet. That’s because the required integration with Java is quite high
(extending a java class) and JRuby couldn’t yet compile a script to
‘proper’
java bytecode (it faked the ‘extending part’). But it seems 1.5 has
fixed
this issue - so I wanted to finally integrate it in my site. I tried the
jruby-rake-plugin, but I’m not really familiar with rake, I tried
mkristian’s http://github.com/mkristian/jruby-maven-plugins
jruby-maven-plugin , but it doesn’t support 1.5 yet and I tried the
maven
antrun plugin and using JRuby to compile a script file, but I couldn’t
make
it work.

So I’m clueless

  • I either a) find a working plugin, b) figure out how to use rake from
    Maven for my purpose or c) find out how I use antrun for that.

Thanks for listening :slight_smile:

Cheers,
stephanos

View this message in context:
http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28343958.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

BTW- does that make me a white belt?

On Apr 23, 2010, at 4:05 PM, Gary W. wrote:

pom.xml:



output:
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Building jar: /some/path/to/dir/temp/target/test-0.1.jar
[INFO] ------------------------------------------------------------------------
$ jruby -v

http://codingkata.org codingkata.org which provides programming exercises
mkristian’s http://github.com/mkristian/jruby-maven-plugins
Cheers,


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks for your detailed tutorial! It definitely earns you a white belt
:slight_smile:

But you’d get the black belt if you tell me how I can do this WITHOUT
having
jruby manually copied/installed on the PC.
All my katas are zero-install (except for JavaFX obviously) - so that’s
the
last big issue I’m facing …

Cheers,
stephanos

View this message in context:
http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28349918.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Check out the pom.xml and tests within:
http://kenai.com/projects/jruby-embed/sources/sources/

Looks to be based on JRuby 1.4 and Apache Bean Scripting Framework.
Looks like the earlier version of bsf didn’t use JSR-223 and the latest
version (which I think requires Java 1.6) does.

However for jruby-embed’s tests, it looks like (but I might be wrong) it
assumes you have jruby installed in some places (at least in the tests
there are references to jruby’s path). Not that it is a game changer- it
just isn’t the full solution that you’re looking for.

But jruby-complete (jar) has everything you need to compile and run what
you are looking to do I think, so the first step would be having that as
a dependency.

Beyond, that I would have looked at jruby-maven-plugin’s jruby:run goal
mentioned here ( http://mojo.codehaus.org/jruby-maven-plugin/howto.html
) but I think you said previously that wouldn’t work for you.

I don’t know if I’d go down the road of trying to actually call JRuby’s
compiler via Java (I think Compile class is in a Ruby (JRuby) file, even
though the JITCompiler etc are Java classes) without using bsf, etc. But
you could maybe just have Maven call an ant task to get the JRuby
source, extract it, and call jruby (script file) all from within Maven’s
pom.xml. I wouldn’t say that is the best approach (I’d work on fixing
jruby-maven-plugin for example instead if you wanted to really
contribute), but it might be the simplest approach if you can’t rely on
anything else.

Don’t know whether this helps or not. You’ve probably already looked
into all of that.

Gary

On Apr 24, 2010, at 7:56 AM, stephanos wrote:


View this message in context: http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28349918.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks for all your time and support! Will look into all possibilities
:slight_smile:

Gary W. wrote:

there are references to jruby’s path). Not that it is a game changer- it
I don’t know if I’d go down the road of trying to actually call JRuby’s
all of that.

But you’d get the black belt if you tell me how I can do this WITHOUT
http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28349918.html


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


View this message in context:
http://old.nabble.com/JRuby-1.5-and-Maven-tp28342154p28374228.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Stephanos,

Does this help?

  1. create a directory called temp:

mkdir temp

  1. copy these two files into it:

pom.xml:

<?xml version="1.0"?>


4.0.0
test
test
test
0.1



maven-antrun-plugin


install










run






somescript.rb:

puts ‘Hello world’

  1. run maven

mvn install

output:

$ mvn install
[INFO] Scanning for projects…
[INFO]

[INFO] Building test
[INFO] task-segment: [install]
[INFO]

[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (MacRoman actually) to copy filtered
resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
/some/path/to/dir/temp/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] No sources to compile
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (MacRoman actually) to copy filtered
resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory
/some/path/to/dir/temp/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] No sources to compile
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [jar:jar {execution: default-jar}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /some/path/to/dir/temp/target/test-0.1.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing /some/path/to/dir/temp/target/test-0.1.jar to
/Users/username/.m2/repository/test/test/0.1/test-0.1.jar
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[exec] Compiling somescript.rb to class somescript
[exec] Compiling all in ‘/some/path/to/dir/temp’…
[exec] Compiling ./somescript.rb to class somescript
[INFO] Executed tasks
[INFO]

[INFO] BUILD SUCCESSFUL
[INFO]

[INFO] Total time: 4 seconds
[INFO] Finished at: Fri Apr 23 15:59:56 EDT 2010
[INFO] Final Memory: 10M/508M
[INFO]

file created:
somescript.class

I did this with:

$ jruby -v
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2009-11-02 69fbfa3) (Java
HotSpot™ Client VM 1.5.0_19) [i386-java]

$ mvn -v
Apache Maven 2.2.0 (r788681; 2009-06-26 09:04:01-0400)
Java version: 1.5.0_19
Java home:
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home
Default locale: en_US, platform encoding: MacRoman
OS name: “mac os x” version: “10.6.2” arch: “i386” Family: “unix”

And yes I’m using Java 1.5 in OS X 10.6.2. :stuck_out_tongue: Makes things easier
sometimes (
http://tedwise.com/2009/09/25/using-java-1-5-and-java-1-4-on-snow-leopard/
) and other times not so good (like when the Firefox guys say “that’s
why you are all screwed up” when I report a bug).

Hope that helps,
Gary

On Apr 23, 2010, at 1:00 PM, stephanos wrote:

yet. That’s because the required integration with Java is quite high

  • I either a) find a working plugin, b) figure out how to use rake from

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs