Get name of the executed jar

3

I would like to get the name of the .jar running.

The .jar will have dynamic names, modified as some hash, and would like that when executed, it would identify its own file name.

The user.dir of System.getProperty brings me the path where it is, but as the name will be modified constantly, I would like it when it is executed, it would identify its new name.

    
asked by anonymous 23.12.2016 / 13:14

1 answer

6

Try this, as SOEn response :

String jarName = new java.io.File(SomeClassInYourJar.class.getProtectionDomain()
      .getCodeSource()
      .getLocation()
      .toURI()
      .getPath())
      .getName();
    
23.12.2016 / 13:21