1

I would like to display all the artifact name along with its implementation version details deployed in an jboss eap server in a web application deployed in same server.How can i read the manifest file from a war file in another webapplication.

sce.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"); works only to get the manifest file from the war servlet context.

public class Version implements ServletContextListener {
    private static final Logger LOG = LoggerFactory.getLogger(Version.class);

    private static Attributes sMainManifestAttributes;
    public static final String ARTIFACT_ID = "Implementation-Title";
    public static final String ARTIFACT_VERSION = "Implementation-Version";

    /**
     * Read the manifest from /META-INF/MANIFEST.MF
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        try {
            ServletContext application = sce.getServletContext();
            InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
            Manifest manifest = new Manifest(inputStream);
            sMainManifestAttributes = manifest.getMainAttributes();
            LOG.info("BIH Artifact Name:" + sMainManifestAttributes.getValue(ARTIFACT_ID) + " Artifact Version :"
                    + sMainManifestAttributes.getValue(ARTIFACT_VERSION));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        sMainManifestAttributes = null;
    }

    /**
     * Generic querying of the manifest.
     * 
     * @return The result, as run through String.trim()
     */
    public static String getValue(String name) {
        return sMainManifestAttributes.getValue(name).trim();
    }


}
Ravi
  • 1,247
  • 4
  • 15
  • 35
  • Since wars are isolated as per the specification you'd have to access them via the file system and since they basically are zip files it should be straight forward to do (read the zip entry `/META-INF/MANIFEST.MF`). – Thomas Aug 06 '18 at 16:46
  • @Thomas the file system location can change anytime.and it can cause issue while deployment if the file is read at same time.is there any other way to implement?? – Ravi Aug 06 '18 at 16:51
  • Well, afaik all the deployed applications should be listed in the JNDI so you could try to find them there. Or you could try to get the listing that JMX-console has (there is a port for JBoss 7 which should be equivalent to EAP 6, right?) and see if you can get what you need from there. – Thomas Aug 06 '18 at 17:01
  • The JNDI view doesnt display the maven impementation version.It just has the artifact name and env .I need the maven impementation version. – Ravi Aug 07 '18 at 16:59
  • I tried inspecting the jboss.as mbeans as well and it also doesnt contain the maven impementation version details. – Ravi Aug 07 '18 at 17:02
  • Well, in that case the only thing I could think of would be to use that information to somehow get a handle on the artifact location in the filesystem. Btw, what do you need that info for? Maybe there's a complete different approach to achieve your end goal. – Thomas Aug 07 '18 at 19:52
  • My goal is to display a web page with the artifacts name along with its version name for the deployed components.. – Ravi Aug 08 '18 at 05:45
  • If you use Spring I found useful this solution: https://stackoverflow.com/a/25700939/2186777 – fl4l Aug 18 '23 at 14:59

0 Answers0