Use Maven/Ant to compile JRuby script to JAR

Hi folks,

here is an example of what I want to do:
I have a ruby script ‘prime.rb’ with a method ‘isPrimeNumber(num)’ which
should be compiled into a JAR ‘prime.jar’. It should be possible to use
this JAR from a Java class main.java which compiles to main.jar and
calls the described method to check if a number is a prime number.
=> basically I need to compile the JRuby script to a Java bytecode
compatible JAR

The conditions are:

  • everything must be done via Maven (note: Maven ‘knows’ Ant as well)
  • no program can be manually installed - only Maven and the JDK are
    present on the PC

I asked a similar question quite a while ago
(JRuby 1.5 and Maven - JRuby - Ruby-Forum), but didn’t get
satisfactory replies - yet I am still interested in this.

Cheers,
Stephanos

bump

BTW, to simplify my question: Is there any way to use the
jruby-complete.jar (via Ant) in order to compile a script.rb to
script.class ?

Stephan Be wrote:

Hi folks,

here is an example of what I want to do:
I have a ruby script ‘prime.rb’ with a method ‘isPrimeNumber(num)’ which
should be compiled into a JAR ‘prime.jar’. It should be possible to use
this JAR from a Java class main.java which compiles to main.jar and
calls the described method to check if a number is a prime number.
=> basically I need to compile the JRuby script to a Java bytecode
compatible JAR

The conditions are:

  • everything must be done via Maven (note: Maven ‘knows’ Ant as well)
  • no program can be manually installed - only Maven and the JDK are
    present on the PC

I asked a similar question quite a while ago
(JRuby 1.5 and Maven - JRuby - Ruby-Forum), but didn’t get
satisfactory replies - yet I am still interested in this.

Cheers,
Stephanos

Stephan,

From the original thread: JRuby 1.5 and Maven - JRuby - Ruby-Forum

  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’

Except beyond that add a task that adds “${basedir}” to the classpath
(via ant config of the ant task in the maven pom.xml) and calls
jruby.jar somescript (without the .rb). Maybe you could add a task to
grab the jruby jar from some external source if you couldn’t use it as a
dependency.

Good luck,
Gary

Hm, I’m not sure I understand what is actually different to the post you
did originally.

Are you saying I should simply use jrubyc?
Or are you saying I should use the jruby.jar and execute the script
‘dynamically’?

Either way, the requirements are not fulfilled (“no program can be
manually installed” [!jrubyc] and/or “Java bytecode” [!dynamic]).

Or am I not getting it?

I was hoping for something like
Has anyone used or written an Ant task to compile (Rhino) JavaScript to Java bytecode? - Stack Overflow’.
Isn’t the code for jrubyc inside the jruby-complete.jar anyway?

Cheers,
stephanos

Gary W. wrote:

Stephan,

From the original thread: JRuby 1.5 and Maven - JRuby - Ruby-Forum

  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’

Except beyond that add a task that adds “${basedir}” to the classpath
(via ant config of the ant task in the maven pom.xml) and calls
jruby.jar somescript (without the .rb). Maybe you could add a task to
grab the jruby jar from some external source if you couldn’t use it as a
dependency.

Good luck,
Gary