Hi All,
As you all know In web application inside web directory there is a META-INF directory. Inside which we have MANIFEST.MF that holds version information. I have to read the MANIFEST.MF from this directrory. Need the manifest info for the purpose of build info and have to show in footer of each page. It's easy to read it in case of JAR file and while searching on net I got mostly examples on jar,classpath related Manifest. But my requirement was to read web/META-INF/MANIFEST.MF file.
So I am posting here what I done:
Inside web application then using the ServletContext.getResourceAsStream
method should work and same I used.
// for a Servlet, you can get the ServletContext like this
ServletContext aContext = getServletConfig().getServletContext();
InputStream inputStream = aContext.getResourceAsStream("/META-INF/MANIFEST.MF");
In Spring application do following inside controller:
//Build Info
ServletContext aContext= getServletContext();
InputStream fis =aContext.getResourceAsStream("/META-INF/MANIFEST.MF");
Hope this helps you 🙂 . Do post your comments
Решил добавить RSS и получать новости, мне лично понравилось, что написал автор
Your post solved my problem 🙂
Just to add for Spring 3.0:
@Controller
public class VersionController {
@RequestMapping(“/version”)
public @ResponseBody
Map getAppVersionData(HttpServletRequest req) throws IOException {
Map map = new HashMap();
ServletContext aContext = req.getSession().getServletContext();
InputStream fis = aContext.getResourceAsStream(“/META-INF/MANIFEST.MF”);
Properties p = new Properties();
p.load( fis );
. . .
Thanks!
Thanks,
This really works.
I need to get PROJECT path.
Actually I’m developing a html mail. I save my template in one location. when uploaded to server the path?
try {
ServletContext aContext = request.getServletContext();
String fis = aContext.getRealPath("/");
System.out.println(fis);
} catch (Exception e) {
}
I got what i need from featuriz.
hear is the code.
try {
ServletContext aContext = request.getServletContext();
String fis = aContext.getResource("/").getPath().replaceAll("/WEB-INF/classes/", "");
System.out.println(fis);
} catch (Exception e) {
}