1

I'm using Groovy's CliBuilder to parse command line arguments and generate a usage message when the command line is incorrect. As part of the usage message, I'd like to be able to print the actual name of the program used (since the version number changes with each build). How can I get the name of the program used?

I'd love to be able to do something like:

def cli = new CliBuilder(usage: "java -jar ${this.name} -db DBCONNECTIONFILE")

but all I seem to be able to obtain are the arguments that come after the program name.

Perhaps I can get it from the pom, but I don't understand how I can grab that from the pom file short of reading in and parsing the pom.

GLaDOS
  • 683
  • 1
  • 14
  • 29

1 Answers1

1

Sounds like you want to get the name of the currently executing jar. This is covered in How to get the path of a running JAR file?

new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

then calling .getName(). If you just want the path, then you can use

MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()
Community
  • 1
  • 1
Riley Mottus
  • 73
  • 1
  • 5