On Fri, Nov 14, 2014 at 3:28 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Matt,
>
> On 11/14/14 1:14 PM, Matt Newell wrote:
>> Greetings,
>>
>> I have a need to get version information for classes that I have
>> been packaged in a war, and loaded into Tomcat 7.0.trunk on Windows
>> 7. For example:
>>
>>
>> System.out.println(this.getClass().getPackage().getImplementationVersion());
>>
>>  Assuming my.war/META-INF/MANIFEST.MF: Manifest-Version: 1.0
>> Implementation-Version: 1.0
>>
>> getImplementationVersion() always returns null.
>>
>> If I review the code for WebappClassLoader the reason for this is
>> clear. All roads lead to findResourceInternal(File, String), line
>> 2983 in 7.x/trunk. This method makes no attempt to load the
>> manifest from the war.
>>
>> My first instinct was that this is a bug. However, I did a quick
>> check using the same scenario using Wildfly 8 and the behavior is
>> the same. Given the clarity of the Tomcat code, and that two
>> robust, well-tested platforms behave the same, I have to assume
>> this is intentional.
>>
>> My question is this: why? Is META-INF/MANIFEST.MF not part of the
>> war standard? I've googled, but am not enough of a java standards
>> wonk to know what docs are authoritative on this topic. I've
>> certainly seen examples that use it.
>
> If Tomcat can't/won't do this, you can always load the manifest
> manually (context.getResource*) and grab the Implementation-Version
> from it.

Chris,

Agreed. Ultimately I am likely to leverage some approach along these
lines. Just thought it was odd that tomcat didn't populate the data
structures I expected.

In my particular case, however, this approach is limiting. My use case
is to get version information from *all* loaded wars. Specifically
pulling resources from ServletContext or the available ClassLoader is
limited to resources within the current war.

java.lang.Package.getPackages() doesn't have this limitation, it seems
to pull packages loaded via all ClassLoaders. But it only works if the
ClassLoader populated the metadata from META-INF/MANIFEST.MF when
loading a class.

Otherwise, I've got to build a startup hook into each war that reads
its manifest, and writes version info to some global space.
Properties, maybe? Ugly. But, ya do what ya gotta.

Thanks,
  -- m.

>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> Comment: GPGTools - http://gpgtools.org
>
> iQIcBAEBCAAGBQJUZmXoAAoJEBzwKT+lPKRYpQgP+gPdc9rySB7Fc3/L02PuoQkj
> K9W+XLA9K/rCb9hWaS2v8EZajR/S9Vf1EvZtmjvtkoTH5U/w3J+kDfH1K/rmzePZ
> aXxJajN487Oo22IF4IKe9YafaAHdUd40hpdXuFug3RrYLSpVC/+mczrq+bvAlbMq
> VRCEWokTTNrISpekZ/Kw/iVmFUny7YC4wclCE5jt9ziHPIdPJpR2w4AmvdEkiwEv
> 3gqAlTyo7YM5Ty7NWaScA3XlB/69bZfrUhRtBuvtT7wC/Yzk42AJ8VF4xYJ+Wg+S
> PVNERXGEP+O2eRGED2ShqYHEkaxHYldNbpo1q9ozE8yh9WvToJ0pqv5Gl4Z2WrKr
> QX2tPwWuGlqzMiaSWpCf7GfUgeSdo0tEPI9LwzUW74Ra2/NyosG1bsLWIahANJnG
> 5Hu6isQzUbmetaNpn9/FO6id4vS25yICHNH+2RXgw/ekcTqTrkyCoaD7fF+qKD/S
> zikoKVaXTWwK5f2vGzoctp2SLl2PgSj3RhBUs0snxGoDPEz0Vt02xi5f7nXBS09m
> 3mdLudyP4Z7nD/fKYYu+w9vxc/hx1Y357lQi3ES2GU2dC2YjAqyiF2n8Nw2k3M0v
> UJxIb9qCyT7a38buTMRt/zLKoG4UyOy41boB6F6A/2050P6QFWLOhsBOvDW4bQlS
> oz32lftds1Y6wlsarMoh
> =09hK
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to