On 05/03/2007, at 5:39 PM, Caldarale, Charles R wrote:

From: Paul A. Hoadley [mailto:[EMAIL PROTECTED]
Subject: Re: Using getImplementationVersion() to read MANIFEST.MF

1.  How can I read the value of the property from some arbitrary
class, say /WEB-INF/classes/some/package/Version.class?

You can use the following construct to create an InputStream pointing to the manifest file and then pass that to a Properties.load() to retrieve
all the keys and values:

    Properties prop = new Properties();

prop.load(getServletContext().getResourceAsStream("/META-INF/ MANIFEST.MF
"));

I ended up doing something quite like this (though using java.util.jar.Manifest), but I was initially stuck at this point. What I may not have made sufficiently clear in my original post is that the class I'm using isn't a servlet itself: it's a JavaBean that I'm instantiating from a JSP page (actually, from a custom tag written as a JSPX fragment). Consequently, it couldn't call getServletContext(). It took me a while, but I finally thought of a solution---pass the ServletContext to the bean from the JSP via a property of the bean:

<jsp:setProperty name="version" property="servletContext" value="$ {pageContext.servletContext}"/>

Is this the idiomatic way for a non-servlet object to obtain a ServletContext, or am I overlooking something easier or more appropriate?


--
Paul.

w  http://logicsquad.net/
h  http://paul.hoadley.name/



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to