Created
July 5, 2022 19:04
-
-
Save twopoint718/26443f4986a87f45b4c3de9cbded5cbb to your computer and use it in GitHub Desktop.
Modify a `pom.xml` file in place so that when using `mvn package` it generates an executable jar file.
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
if ARGV.length == 0 | |
puts "\nUSAGE:\n\tpom_editor.rb path/to/pom.xml\n\n" | |
end | |
filename = ARGV[0] | |
@doc = Nokogiri::XML.parse(File.read(filename)) | |
group_id = @doc.at_css("groupId").text | |
jar_config = [ | |
' <configuration>', | |
' <archive>', | |
' <manifest>', | |
' <addClasspath>true</addClasspath>', | |
" <mainClass>#{group_id}.App</mainClass>", | |
' </manifest>', | |
' </archive>', | |
" </configuration>\n "].join("\n") | |
@doc.search('plugins plugin').each do |plugin| | |
if plugin.at_css('artifactId').text == 'maven-jar-plugin' | |
plugin.add_child(jar_config) | |
end | |
end | |
File.rename(filename, filename + '.bak') | |
File.write(filename, @doc.to_xml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment