Skip to content

Instantly share code, notes, and snippets.

@changmason
Created May 2, 2011 09:25
Show Gist options
  • Save changmason/951357 to your computer and use it in GitHub Desktop.
Save changmason/951357 to your computer and use it in GitHub Desktop.
Tasks to compile the jruby project into a standalone jar
# Compile the jruby project into a standalone jar, doc refers to
# https://github.com/jruby/jruby/wiki/StandaloneJarsAndClasses
namespace :pkg do
PGEM_FILES = []
PLIB_FILES = []
PROJECT_JAR = "package/project_name.jar"
JRUBY_JAR = "jruby-complete-1.6.1.jar"
BOOTSTRAP = "jar-bootstrap.rb"
desc "compile and build the package"
task :build => [:pkg_dir, :copy_gems, :compile_lib, :project_jar]
desc "destroy the built package"
task :clean do
rm_rf "package"
end
desc "run the built package"
task :run => :build do
sh "java -jar #{PROJECT_JAR}"
end
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# the "package" directory task
directory "package"
task :pkg_dir => "package"
# the copy gems task
GEM_FILES = FileList['gems/**/*.*']
GEM_FILES.each do |gemf|
pgemf = File.join("package", gemf)
pgemdir = File.dirname(pgemf)
mkdir_p(pgemdir) unless File.exist?(pgemdir)
file pgemf => gemf do
cp(gemf, pgemf)
raise "Fail to copy #{gemf}" if not File.exist?(pgemf)
end
PGEM_FILES << pgemf
end
task :copy_gems => PGEM_FILES
# the compile lib task
LIB_FILES = FileList['lib/**/*.*']
LIB_FILES.each do |libf|
plibf = File.join("package", libf)
plibdir = File.dirname(plibf)
mkdir_p(plibdir) unless File.exist?(plibdir)
if File.extname(libf) == '.rb'
plibf = plibf.sub(".rb", ".class")
file plibf => libf do
sh "jrubyc \"#{libf}\" --target package/"
raise "Fail to compile #{libf}" if not File.exist?(plibf)
end
else
file plibf => libf do
cp(libf, plibf)
raise "Fail to copy #{libf}" if not File.exist?(plibf)
end
end
PLIB_FILES << plibf
end
task :compile_lib => PLIB_FILES
# the project jar task
file PROJECT_JAR => [JRUBY_JAR, BOOTSTRAP] do
cp(JRUBY_JAR, PROJECT_JAR)
sh "jar ufe #{PROJECT_JAR} org.jruby.JarBootstrapMain #{BOOTSTRAP}"
end
task :project_jar => PROJECT_JAR
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment