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

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-'require'-via-jruby-maven-plugin-tp30764600p30764600.html
Sent from the JRuby - User mailing list archive at Nabble.com.

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

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?

kristian-2 wrote:

On Wed, Jan 26, 2011 at 10:57 AM, stug23 [email protected] wrote:

in a Maven project using the jruby-maven-plugin. The jruby-maven-plugin
rubygems

[INFO] — jruby-maven-plugin:0.23.0:jruby (test-hello) @
[WARNING] from

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


View this message in context:
http://old.nabble.com/Executing-ruby-script-with-a-'require'-via-jruby-maven-plugin-tp30764600p30764684.html
Sent from the JRuby - User mailing list archive at Nabble.com.

needed to fix a few little things on github - hope it helped anyways.

regards Kristian

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.

:slight_smile:

kristian-2 wrote:

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

[WARNING]

you got me with your configuration. nested gem dependencies with the

in a Maven project using the jruby-maven-plugin. The

                                           <id>test-hello</id>
                                   <file>hello.rb</file>

file:/Users/me/.m2/repository/org/jruby/jruby-complete/1.5.6/jruby-complete-1.5.6.jar!/META-INF/jruby.h

a

http://old.nabble.com/Executing-ruby-script-with-a-'require'-via-jruby-maven-plugin-tp30764600p30764600.html


View this message in context:
http://old.nabble.com/Executing-ruby-script-with-a-'require'-via-jruby-maven-plugin-tp30764600p30774088.html
Sent from the JRuby - User mailing list archive at Nabble.com.

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