tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: WebappClassLoader and MANIFEST.MF in WARs
Date Sat, 15 Nov 2014 00:08:04 GMT
2014-11-15 0:57 GMT+03:00 Matt Newell <dycsail@gmail.com>:
> On Fri, Nov 14, 2014 at 3:28 PM, Christopher Schultz
> <chris@christopherschultz.net> wrote:
>> 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.

1. What if the web application does not have a war file, but is
deployed as an expanded directory?

2. Please find some specification references.

3. If there were a manifest for the WEB-INF/classes/ I would wonder
whether it is META-INF/MANIFEST.MF or
WEB-INF/classes/META-INF/MANIFEST.MF.  Why prefer the former rather
than the latter?  I think that none of them is applicable.

4. Are there any precedents? Discussions?


Best regards,
Konstantin Kolinko

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


Mime
View raw message