Java ClassLoader Load getManifestInfo()

Here you can find the source of getManifestInfo()

Description

get Manifest Info

License

Open Source License

Declaration

public static String getManifestInfo() 

Method Source Code

//package com.java2s;
/*   Copyright (C) 2011 Marius C. Silaghi
  Author: Marius Silaghi: msilaghi@fit.edu
  Florida Tech, Human Decision Support Systems Laboratory
       //from w  w  w  .  j  a v a 2  s. c  o m
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation; either the current version of the License, or
   (at your option) any later version.
       
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
      
  You should have received a copy of the GNU Affero General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */

import java.util.Enumeration;

import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import java.io.IOException;
import java.io.InputStream;

import java.net.URL;

public class Main {
    public static String getManifestInfo() {
        Enumeration resEnum;
        try {
            resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
            while (resEnum.hasMoreElements()) {
                try {
                    URL url = (URL) resEnum.nextElement();
                    InputStream is = url.openStream();
                    if (is != null) {
                        Manifest manifest = new Manifest(is);
                        Attributes mainAttribs = manifest.getMainAttributes();
                        for (Object val : mainAttribs.keySet()) {
                            System.out.println("Key: " + val + ": " + mainAttribs.get(val));
                        }

                        String version = mainAttribs.getValue("Implementation-Version");
                        if (version != null) {
                            return version;
                        }
                    }
                } catch (Exception e) {
                    // Silently ignore wrong manifests on classpath?
                }
            }
        } catch (IOException e1) {
            // Silently ignore wrong manifests on classpath?
        }
        return null;
    }
}

Related

  1. getImageFilename(String name)
  2. getInputStream(String name)
  3. getLibKoyaVersion()
  4. getLocalFile(final String aLocalPath)
  5. getLog4jPropertiesLocation()
  6. getMetadataSpecialSymbolsXml()
  7. getPath(final String fileName)
  8. getPath(String resoureLocation)
  9. getProhibitedProxyInterfaces()