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.