Is there a way to get version of current java mail api programmatically?

Viewed 2008

I need the version of the current java mail api jar used in the classpath. I can not use the

IMAPStore.class.getPackage().getImplementaionVersion() 

because it returns null in our productive environment, because of

  • the custom class loader (jarsafe)

    or

  • we extract all jars (including mail api and other 3rd party jars/libraries) in our release deployment products and put them into a single jar and the manifest information gets lost.

Does mail api support a method such as System.getProperty etc?

1 Answers

If nothing else works ugly solution might be to grep mail api jar name from classpath. It might contain the version.

However if you are 'shading' all jars to a single jar i think also this information is lost from classpath information since there is no more specific jar for mail api.

Guess that

getPackage().getImplementationVersion()

uses property file / manifest that shading exludes and therefore returns null.

Perhaps you could check the process that creates the shaded jar. Maybe you can add there a step that copies the version for example as an properties file that you can later read.

If it is about already 'deployed' system and above is no more possible to implement i guess that options for programmatic solutions are very few.

Related