public
Last active

Buildr uberjar task using one-jar

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# XXX: Set the deps you want
deps = []
deps << "com.thoughtworks.xstream:xstream:jar:1.3.1"
deps << "org.quartz-scheduler:quartz:jar:1.8.5"
 
task :uberjar => :package do |t|
assembly_dir = "target/assembly"
FileUtils.mkdir_p( "#{assembly_dir}/lib" )
FileUtils.mkdir_p( "#{assembly_dir}/main" )
FileUtils.copy "target/#{project.name}-#{project.version}.jar", "#{assembly_dir}/main"
artifacts = Buildr.artifacts(deps).map(&:to_s)
artifacts.each do |artifact|
FileUtils.copy artifact, "#{assembly_dir}/lib"
end
# XXX: path to one-jar-boot-0.97.jar - http://one-jar.sourceforge.net/
Unzip.new( assembly_dir => "/path/to/one-jar-boot-0.97.jar" ).extract
FileUtils.rm_rf "#{assembly_dir}/src"
File.open( "#{assembly_dir}/boot-manifest.mf", 'a') do |f|
# XXX: Set Java main class
f.write("One-Jar-Main-Class: com.example.Server\n")
end
`cd target/assembly; jar -cvfm ../#{project.name}-uberjar-#{project.version}.jar boot-manifest.mf .`
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.