org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1054 on runing Rawr 1.6.6

125 views
Skip to first unread message

Sam Xiao

unread,
Sep 13, 2013, 7:22:56 PM9/13/13
to rawr...@googlegroups.com
Hello all,


First time using 'rawr' to bundle a gem executable and have this error after running "rake rawr:jar". Am I doing anything wrong here or am I missing anything?

╭─sxiao at thq-m-sxiao01 in ~/workspace/testgem on master✘✘✘ using ‹jruby-1.7.4@testgem›
╰─○ rake rawr:jar
/Users/sxiao/.rvm/gems/jruby-1.7.4@testgem/gems/rawr-1.6.6/lib/zip/zip.rb:28: Use RbConfig instead of obsolete and deprecated Config.
cp lib/java/jruby-complete.jar package/jar/lib/java/jruby-complete.jar
╭─sxiao at thq-m-sxiao01 in ~/workspace/testgem on master✘✘✘ using ‹jruby-1.7.4@testgem›
╰─○ java -jar package/jar/testgem.jar version
Exception in thread "main" org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- main
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1054)
at RUBY.require(jar:file:/Users/sxiao/workspace/testgem/package/jar/lib/java/jruby-complete.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/custom_require.rb:36)
at RUBY.(root)(<script>:1)

James Britt

unread,
Sep 13, 2013, 9:51:22 PM9/13/13
to rawr...@googlegroups.com
Sam Xiao wrote:
> Hello all,
>
>
> First time using 'rawr' to bundle a gem executable and have this error
> after running "rake rawr:jar". Am I doing anything wrong here or am I
> missing anything?
>


What version of rawr?

James

--

jamesbritt.com - Live curious
justthebestparts.com - Feed your head
neurogami.com - Hack your world

James Britt

unread,
Sep 13, 2013, 9:53:26 PM9/13/13
to rawr...@googlegroups.com


On Friday, September 13, 2013 4:22:56 PM UTC-7, Sam Xiao wrote:
Hello all,



Hi.
 
First time using 'rawr' to bundle a gem executable and have this error after running "rake rawr:jar". Am I doing anything wrong here or am I missing anything?


Do you in fact have a file main.rb?

James

Sam Xiao

unread,
Sep 15, 2013, 2:52:54 AM9/15/13
to rawr...@googlegroups.com
Rawr 1.6.6

Sam Xiao

unread,
Sep 15, 2013, 2:54:04 AM9/15/13
to rawr...@googlegroups.com
I don't have 'main.rb', but I never should need it. I just generate as I follow the instruction. Anything that I'm missing?

James Britt

unread,
Sep 15, 2013, 12:33:21 PM9/15/13
to rawr...@googlegroups.com


On Saturday, September 14, 2013 11:54:04 PM UTC-7, Sam Xiao wrote:
I don't have 'main.rb', but I never should need it. I just generate as I follow the instruction. Anything that I'm missing?


Yes: main.rb

The way rawr works is it creates a Java file that exists as an entry point for running Ruby code from a jar.

It looks at the values in build_configuration.rb to see what Ruby file it needs to eval in order to start your program.

By default this is set to "src/main.rb"

You can change this in build_configuration.rb to whatever is the main file of your program, or just call your main file "main.rb".

James

Sam Xiao

unread,
Sep 15, 2013, 5:21:25 PM9/15/13
to rawr...@googlegroups.com
I used Thor as my CLI framework.

Everything can be run as a single executable under bin/mygem, and it looks like this:

#!/usr/bin/env ruby
require 'mygem'
Mygem::Core.start

Can I just point to that one?

Thanks,
Sam

James Britt

unread,
Sep 15, 2013, 10:44:31 PM9/15/13
to rawr...@googlegroups.com
Sam Xiao wrote:
> I used Thor as my CLI framework.
>
> Everything can be run as a single executable under* bin/mygem*, and it
> looks like this:
>
> #!/usr/bin/env ruby
> require 'mygem'
> Mygem::Core.start
>
>
> Can I just point to that one?

I have no idea.

rawr assumes you are not using any gems, since the whole idea is to
package up all your code into a standalone (except for a JRE) program.

It assumes you would otherwise run your program as

ruby /src/somefile.rb

or

jruby /src/somefile.rb


and all required files and libraries are within the project folder.

I have no idea how to get it to know anything about Thor.

Sam Xiao

unread,
Sep 16, 2013, 2:26:51 PM9/16/13
to rawr...@googlegroups.com
Is it possible to package all libraries gems into this executable jar?  This is what on mygem.gemspec
  spec.add_dependency "thor"
  spec.add_dependency "json"
  spec.add_dependency "rest-client"

Running this works:
$ jruby bin/mygem version


My build_configuration.rb looks like this:

configuration do |c|
c.project_name = "mygem"
c.executable_type = "console"
c.main_ruby_file = "bin/mygem"
c.source_dirs = ['src', 'lib/gem']
end

James Britt

unread,
Sep 17, 2013, 12:00:22 PM9/17/13
to rawr...@googlegroups.com
Sam Xiao wrote:
> Is it possible to package all libraries gems into this executable jar?
> This is what on *mygem.gemspec*
>
> spec.add_dependency "thor"
> spec.add_dependency "json"
> spec.add_dependency "rest-client"
>


In general, all references to gems need to be changed to loading from a
local file in a relative path. Typically this means running "gem
unpack". For example:


gem unpack thor

This creates (in my case) a folder named "thor-0.18.1", then in my code
I would need to explicitly add "thor-0.18.1/lib" to the load path and
make sure that the "thor-0.18.1" folder gets included in my rawr jar
packaging.

You would have to do this for all gems you are using and for any gems
any of *those* gems are using, and so on.


>
> Running this works:
>
> $ jruby bin/mygem version
>
>
>
> My build_configuration.rb looks like this:
>
> configuration do |c|
> c.project_name = "mygem"
> c.executable_type = "console"
> c.main_ruby_file = "bin/mygem"
> c.source_dirs = ['src', 'lib/gem']
> end
>
>


That may work if you've unpacked all the needed gem files into the
"lib/gem" folder and made sure all of their <gemname>/lib folders are
added to the load path inside of your program (e.g. inside of
manifest.rb, or at the start of whatever is playing the role of your
main Ruby file).

It's hard for me to give specific instructions for every scenario; you
basically have to work with the main Rawr concept that *all* files
needed by your program (aside from what is part of the standard JRuby
distro) must be explicitly included in your packaged jar, and their load
paths explicitly made known to your main application code.

amiracam

unread,
Sep 25, 2013, 1:12:08 PM9/25/13
to rawr...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages