[jruby-user] Executing ruby script with a 'require' via jruby-maven-plugin

9 views
Skip to first unread message

stug23

unread,
Jan 26, 2011, 12:27:59 AM1/26/11
to us...@jruby.codehaus.org

I found this informative article in Kristian's Blog that shows how to create
a Maven project from a ruby gem and then install the Maven artifact (gem
package type) in the local Maven repository:

<http://blog.mkristian.tk/2010_08_01_archive.html>

I then wanted to use the ruby gem as a Maven dependency to run a ruby script
in a Maven project using the jruby-maven-plugin. The jruby-maven-plugin
section of the pom.xml looks like the following:

<plugin>
<groupId>de.saumya.mojo</groupId>
<artifactId>jruby-maven-plugin</artifactId>
<version>0.23.0</version>
<dependencies>
<dependency>
<groupId>rubygems</groupId>
<artifactId>rubyzip2</artifactId>
<version>2.0.1</version>
<type>gem</type>
</dependency>
</dependencies>
<executions>
<execution>
<id>test-hello</id>
<phase>verify</phase>
<goals>
<goal>jruby</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
<configuration>
<file>hello.rb</file>
</configuration>
</plugin>

The gem artifact is installed in the local Maven repository.

There is a require statement in hello.rb for the gem:

require 'rubygems'
require 'zip/zip'
puts "hello from ruby "*20

When I run the Maven build, I get an error:

[INFO] --- jruby-maven-plugin:0.23.0:jruby (test-hello) @
bundled-gem-experiment ---
[WARNING]
file:/Users/me/.m2/repository/org/jruby/jruby-complete/1.5.6/jruby-complete-1.5.6.jar!/META-INF/jruby.home/li
b/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require': no such
file to load -- zip/zip (LoadError)
[WARNING] from
file:/Users/me/.m2/repository/org/jruby/jruby-complete/1.5.6/jruby-complete-1.5.6.jar!/META-INF/jruby.h
ome/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
[WARNING] from
/Users/me/Desktop/Helios/helios_workspace/bundled-gem-experiment/hello.rb:2
[WARNING] from
/Users/me/Desktop/Helios/helios_workspace/bundled-gem-experiment/hello.rb:1:in
`load'
[WARNING] from -e:1

Does the jruby-maven-plugin currently support running a ruby script with a
require that references a Maven gem artifact? Am I doing this incorrectly?

Thanks for any help in getting this to work!


--
View this message in context: http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-via-jruby-maven-plugin-tp30764600p30764600.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


kristian

unread,
Jan 26, 2011, 12:45:47 AM1/26/11
to us...@jruby.codehaus.org
you got me with your configuration. nested gem dependencies with the
plugin configuration is not supported.

can you try it with moving that dependency into the top level.

regards, Kristian

stug23

unread,
Jan 26, 2011, 12:58:18 AM1/26/11
to us...@jruby.codehaus.org

I just tried moving the dependency to the top level. I still see the same
error:

[WARNING]
file:/Users/me/.m2/repository/org/jruby/jruby-complete/1.5.6/jruby-complete-1.5.6.jar!/META-INF/jruby.home/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in


`require': no such file to load -- zip/zip (LoadError)

I guess the part I don't understand is how the jruby-maven-plugin resolves
required gems that are provided as Maven dependencies?

--
View this message in context: http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-via-jruby-maven-plugin-tp30764600p30764684.html

kristian

unread,
Jan 26, 2011, 1:14:39 AM1/26/11
to us...@jruby.codehaus.org
yes, you need to do use the gem-maven-plugin and add a repository
where to get the gems from. I adjusted the integration test in your
manner:

https://github.com/mkristian/jruby-maven-plugins/tree/next/gem-maven-plugin/src/it/exec-file

regards,
Kristian

kristian

unread,
Jan 26, 2011, 3:30:22 AM1/26/11
to us...@jruby.codehaus.org
needed to fix a few little things on github - hope it helped anyways.

regards Kristian

stug23

unread,
Jan 26, 2011, 11:07:11 PM1/26/11
to us...@jruby.codehaus.org

I am now able to successfully reference the gem in the Maven repository and
my script executes correctly!

Many thanks to you Kristian for your excellent work on the maven plugins for
jruby! This will make it much easier to incorporate ruby scripts into Maven
projects.

:-)

--
View this message in context: http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-via-jruby-maven-plugin-tp30764600p30774088.html

Reply all
Reply to author
Forward
0 new messages