Created
June 25, 2013 19:03
-
-
Save JerryPreissler/5861368 to your computer and use it in GitHub Desktop.
Short jruby function to require all jar files from a maven classpath.
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
# Require the jar files from a Maven classpath in JRuby | |
# | |
# ==== Attributes | |
# * +path+ to the project root directory where Maven should be run | |
# | |
def maven_require(path) | |
save_dir = Dir.getwd | |
throw "could not change to dir #{path}" unless Dir.exists?(path) | |
begin | |
Dir.chdir(path) | |
data = %x[mvn -X clean compile] | |
cp = nil | |
lines = data.split("\n") | |
lines.each { |line| | |
if line =~ /classpathElements = \[(.*)\]/ | |
cp = $1 | |
break | |
end | |
} | |
if cp | |
entries = cp.split(",") | |
entries.each {|entry| | |
if entry =~ /(\s*)(.*)\.jar/ | |
jar_path = $2 + ".jar" | |
require jar_path | |
puts "required #{jar_path}" | |
end # if entry | |
} # entries.each | |
end # if cp | |
ensure | |
Dir.chdir(save_dir) if save_dir | |
end | |
return "done" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment