Created
June 17, 2014 04:09
-
-
Save ywjno/77b7e6e73f5443309cdd to your computer and use it in GitHub Desktop.
build_jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
require "json" | |
require "fileutils" | |
conf = JSON.load(File.open(File.expand_path("../conf.json", __FILE__), 'r')) | |
tmp_path = conf['tmp_path'] || File.expand_path("../tmp", __FILE__) | |
FileUtils.rm_rf(tmp_path) if File.exist?(tmp_path) | |
FileUtils.mkdir_p(tmp_path) | |
conf['projects'].map do |project| | |
if project['is_maven'] | |
FileUtils.cp_r("#{project['path']}/target/classes/.", tmp_path) | |
else | |
FileUtils.cp_r("#{project['path']}/bin/.", tmp_path) | |
end | |
end | |
if conf['main_class'] | |
FileUtils.mkdir_p("#{tmp_path}/META-INF") | |
File.open("#{tmp_path}/META-INF/MANIFEST.MF", 'w') do |file| | |
file.puts 'Manifest-Version: 1.0' | |
file.puts "Main-Class: #{conf['main_class']}" | |
file.puts | |
end | |
end | |
require 'zip' | |
jar_name = conf['jar_name'] || 'jar_name' | |
build_path = conf['build_path'] || File.dirname(__FILE__) | |
jar_file = "#{build_path}/#{jar_name}.jar" | |
File.delete jar_file if File.exist?(jar_file) | |
Zip::File.open(jar_file, Zip::File::CREATE) do |zipfile| | |
Dir[File.join(tmp_path, '**', '**')].each do |file| | |
zipfile.add(file.sub(tmp_path, '')[1..-1], file) | |
end | |
end | |
FileUtils.rm_rf(tmp_path) if File.exist?(tmp_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"projects": [ | |
{ | |
"path": "D:/nutzEclipse370/workspace/build-jar" | |
}, | |
{ | |
"path": "D:/github/nutz", | |
"is_maven": true | |
}, | |
{ | |
"path": "D:/github/mongo-java-driver", | |
"is_maven": true | |
}, | |
{ | |
"path": "D:/nutzEclipse370/workspace/nutzmongo" | |
} | |
], | |
"main_class": "com.nutz.extension.build.BuildJar", | |
"jar_name": "build_jar" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment