Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save claudiug/918e958ff41e304106831bdf378afa3e to your computer and use it in GitHub Desktop.
Save claudiug/918e958ff41e304106831bdf378afa3e to your computer and use it in GitHub Desktop.
jruby script in a jar
#contents of sample.rb
cat sample.rb
require './before'
puts "Hello World!"
#contents of before.rb
cat before.rb
puts "Before..."
#running:
>jruby sample.rb
Before...
Hello World!
#now we compile only sample.rb
>jrubyc sample.rb
#an 'ls' now shows
>ls
before.rb sample.class sample.rb
#now we jar it up:
>jar cf app.jar sample.class before.rb
#an 'ls' shows:
>ls
app.jar before.rb sample.class sample.rb
#a jar tvf shows the contents of our jar
>jar tvf app.jar
0 Fri Sep 20 19:51:22 EDT 2019 META-INF/
66 Fri Sep 20 19:51:22 EDT 2019 META-INF/MANIFEST.MF
1185 Fri Sep 20 19:50:06 EDT 2019 sample.class
17 Fri Sep 20 18:46:38 EDT 2019 before.rb
#we run it
>java -cp %JRUBY_JAR%;./app.jar sample
Before...
Hello World!
#btw (for me)
echo %JRUBY_JAR%
C:\languages\ruby\jruby-9.2.8.0\jruby-complete-9.2.8.0.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment