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

**URL:** <https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291>\
**Category:** JRuby\
**Created:** [January 26, 2011, 6:28am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291 "2011-01-26T06:28:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 26, 2011, 6:28am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/1 "2011-01-26T06:28:23Z")

</div>

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](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](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](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![stug23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@stug23](https://www.ruby-forum.com/u/stug23)\
**Post date:** [January 26, 2011, 6:46am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/2 "2011-01-26T06:46:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stug23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@stug23](https://www.ruby-forum.com/u/stug23)\
**Post date:** [January 26, 2011, 6:59am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/3 "2011-01-26T06:59:06Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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](http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-via-jruby-maven-plugin-tp30764600p30764684.html)  
Sent from the JRuby - User mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![stug23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@stug23](https://www.ruby-forum.com/u/stug23)\
**Post date:** [January 26, 2011, 9:30am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/4 "2011-01-26T09:30:46Z")

</div>

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

regards Kristian

---

<div class="post-metadata">

**Author:** ![stug23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@stug23](https://www.ruby-forum.com/u/stug23)\
**Post date:** [January 27, 2011, 5:07am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/5 "2011-01-27T05:07:58Z")

</div>

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.

🙂

kristian-2 wrote:

> >

[https://github.com/mkristian/jruby-maven-plugins/tree/next/gem-maven-plugin/src/it/exec-file](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](http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-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](http://old.nabble.com/Executing-ruby-script-with-a-%27require%27-via-jruby-maven-plugin-tp30764600p30774088.html)  
Sent from the JRuby - User mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![stug23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@stug23](https://www.ruby-forum.com/u/stug23)\
**Post date:** [January 26, 2011, 7:15am UTC](https://www.ruby-forum.com/t/executing-ruby-script-with-a-require-via-jruby-maven-plugin/202291/6 "2011-01-26T07:15:22Z")

</div>

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](https://github.com/mkristian/jruby-maven-plugins/tree/next/gem-maven-plugin/src/it/exec-file)

regards,  
Kristian
