# Creating a simple executable jar containing ruby code

**URL:** https://rubytalk.org/t/creating-a-simple-executable-jar-containing-ruby-code/62485
**Category:** ruby-talk
**Created:** [20 April 2011 23:50 UTC](https://rubytalk.org/t/creating-a-simple-executable-jar-containing-ruby-code/62485 "2011-04-20T23:50:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zenko\_turek](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zenko\_turek](https://rubytalk.org/u/zenko_turek)
#### Post date: [20 April 2011 23:50 UTC](https://rubytalk.org/t/creating-a-simple-executable-jar-containing-ruby-code/62485/1 "2011-04-20T23:50:52Z")

</div>

Hi,

I'm a relative noobie ruby dev and I was poking around with rawr. I  
wrote a simple .rb file and then used rawr to package it into a jar but  
have run into some errors.  
I have brought it down to bare bones to understand how this all works  
so I have one ruby file called rubytest.rb.

I ran

> rake rawr:jar

which produces a package/jar/Test.jar for me. All very well and good  
until I try to execute the jar with

> java -jar package/jar/Test.jar.

This gives me and error of:

$ java -jar package/jar/Tests.jar  
Exception in thread "main" org.jruby.exceptions.RaiseException:  
(LoadError) no such file to load -- main  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1038)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at #\<Class:0x100ac06d4\>.(root)(\<script\>:1)

I'm not sure what is wrong, am I missing something here?

thanks

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![zenko\_turek](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zenko\_turek](https://rubytalk.org/u/zenko_turek)
#### Post date: [21 April 2011 00:06 UTC](https://rubytalk.org/t/creating-a-simple-executable-jar-containing-ruby-code/62485/2 "2011-04-21T00:06:15Z")

</div>

Sorry, just to add that I did try to run the jar file with

java -cp.:/package/jar/lib/java/jruby.jar package/jar/Test.jar

to get and exception error as :

$ java -cp .:package/jar/lib/java/jruby.jar package/jar/Tests.jar  
Exception in thread "main" java.lang.NoClassDefFoundError:  
package/jar/Tests/jar  
Caused by: java.lang.ClassNotFoundException: package.jar.Tests.jar  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.net.URLClassLoader$1.run(Unknown Source)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.security.AccessController.doPrivileged(Native Method)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.net.URLClassLoader.findClass(Unknown Source)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.ClassLoader.loadClass(Unknown Source)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at java.lang.ClassLoader.loadClass(Unknown Source)  
Could not find the main class: package/jar/Tests.jar. Program will  
exit.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

### Author: ![zenko\_turek](https://avatars.discourse-cdn.com/v4/letter/z/d9b06d/32.png) [@zenko\_turek](https://rubytalk.org/u/zenko_turek)
#### Post date: [21 April 2011 19:09 UTC](https://rubytalk.org/t/creating-a-simple-executable-jar-containing-ruby-code/62485/3 "2011-04-21T19:09:01Z")

</div>

Alright I was able to solve the mystery and got it to work. It was a  
question of having a build configuration file setup to point in the  
proper areas; I had some values commented out so now it works.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
