Get executed jar name

Asked

Viewed 294 times

3

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

The . jar will have dynamic names, modified as some hash, and I would like when executed, the same to identify its own file name.

The user.dir of System.getProperty brings me the path where it is, more as the name will be constantly modified, I would like when run, the same identify your new name.

1 answer

6


Try this way as per reply on Soen:

String jarName = new java.io.File(SomeClassInYourJar.class.getProtectionDomain()
      .getCodeSource()
      .getLocation()
      .toURI()
      .getPath())
      .getName();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.