Packaging JRuby binaries into executable jar - jruby

Have downloaded the Jruby binaries on windows, installed the necessary gems i needed. How then do I re-package the whole Jruby binaries into an executable jar ?
thanks.

If you have a JRuby project, simply run
rake jar
to see all available tasks:
rake -T

Related

JRuby Installed with rbenv does not add my gem lib directories to the load path

I installed JRuby 1.7.4 using Rbenv. I've installed several gems using gem install GEMNAME from a shell where jruby-1.7.4 was set as the active ruby-- I confirmed after installation that the gems are in fact present in ~/.rbenv/versions/jruby-1.7.4/lib/ruby/gems/shared/gems. But, when I try to require most of my installed gems from jruby, I get an error. Inspection shows that their lib directories are not on the $LOAD_PATH. Shouldn't all the lib dirs in the gem directories I specified above automatically be there? If not, how do I get them to show up there?

How to upgrade to a newer version of jruby

I used the jruby zip executable to install 1.6.2, but it looks like they have released 1.6.4. How should I migrate from 1.6.2 to 1.6.4, should I have to re-install or is there a different command.
Mostly all you need to do is reinstall gems on the newly-unpacked JRuby (recommended), or migrate your existing gem installs by copying the lib/ruby/gems/* over to the new location. There's no automated update tool for JRuby itself right now.
Unpack new Jruby
export JRUBY_HOME=/path/to/jruby
export PATH=$PATH:$JRUBY_HOME/bin
Maybe even push the above to .bashrc
Add a list of required Gems to your Gemfile.
To reinstall Gems if needed the best way to do it is as follows
Jruby -S gem install bundler
Cd to /path/to/Gemfile
bundle install

Executing rake tasks on an exploded war on tomcat without jruby being installed

My rails project is deployed to tomcat with the help of warbler, but I need to be able to run rake tasks on that server.
Stay tuned. I hope to have this capability in Warbler 1.4. Jake Goulding, a community member, has been doing some great work on this.
Until then, a typical approach would be to ensure all your Rake and database scripts are present in the war file, then just unpack it somewhere, cd to WEB-INF inside the unpacked war, and run something like java -cp lib/jruby-core*.jar:lib/jruby-stdlib*.jar org.jruby.Main -S rake -T.

Rawr-created jar throws ClassDefNotFoundError

I am trying to use Rawr to turn a simple 3-file Ruby project into an executable jar to be run on Ubuntu. I ran jruby -S rawr install to create the Rakefile and set up the directory layout. All my .rb files are under the src directory at the root of the project. When I run jruby -S rake rawr:jar, it compiles all the Ruby files and creates the jar just fine. It then places it in my deploy directory along with lib/java/jruby-complete.jar.
I try executing the jar from inside deploy with java -jar hg_analyzer.jar. However, when I do this I am greeted with this error:
Exception in thread "main" <script>:1:in `require': Linkage error loading compiled script; you may need to recompile 'file:/home/marcw/Documents/hg_analyzer/deploy/jar/hg_analyzer.jar!/main.class': java.lang.NoClassDefFoundError: org/jruby/ast/executable/AbstractScript$RuntimeCache (LoadError)
from <script>:1
...internal jruby stack elided...
from Kernel.require(<script>:1)
from (unknown).(unknown)(:1)
I've also tried running it as java -cp lib/java/** -jar hg_analyzer.jar, but to no avail. The Class-Path entry in the jar's manifest file looks okay as well. main.rb is the main Ruby file.
Running java with the -verbose option shows that it is finding the JRuby jar and is loading it from the expected location.
Any ideas?
Figured it out! The problem was that Rawr was downloading version 1.5 of the JRuby runtime and I have version 1.4 of the compiler on my system.

jRuby and Problems with Warbler, RVM, and Tomcat

I've been having a tough time getting jRuby on Rails 3 deployed on Tomcat 6. I got it to work exactly once.
I modified my database.yaml and Gemfile to check for jRuby, something like this:
if defined?(JRUBY_VERSION)
gem 'jdbc-mysql'
#gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
#gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jruby-rack'
gem 'warbler'
else
gem 'mysql'
gem "mongrel"
gem 'ruby-debug'
end
Some environment settings:
$ rvm -v
rvm 1.0.14
$ jruby -v
jruby 1.5.3 (ruby 1.8.7 patchlevel 249) (2010-09-28 7ca06d7) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [x86_64-java]
When I run jruby -S bundle install everything goes smoothly.
It's when I try to do something like rake db:migrate, jruby -S rake db:migrate or warble that I get 50 DEPRECATION WARNINGs and an eventual stackoverflow.
I solved this issue by deleting the warbler plugin, it did not like the line Warbler::Task.new
Next, I ran warble config to give me a config/warbler.rb file.
And finally, warble to create my .war file. So far so good.
Now I move the .war file to my Tomcat webapps. Everything works fine except for an error:
Oct 10, 2010 1:34:46 AM org.apache.catalina.core.ApplicationContext log
SEVERE: Application Error
org.jruby.rack.RackInitializationException:
http://github.com/plataformatec/devise.git (at master) is not checked out.
Please run 'bundle install'
I solved this problem once and only once by going into my webapps/myapp/WEB-INF and running jruby -S bundle install
It no longer works and I have no idea what is going on.
I believe this can be called a bug in the current version of Warbler. Using git repositories in your Gemfile don't quite get staged properly in the war file and Bundler is still looking for a checked out repository on disk.
A future version of Warbler will probably do something along the lines of bundle --deployment when you create the war file.
For now, to work around, you might have to vendor the devise code.
The current version of warbler (1.3.6) will also exhibit this behavior if you build a war file with warbler war. I've found that building with the following command works:
warbler compiled war
Hopefully future versions will address this more completely.