This content has been marked as final.
Show 3 replies
-
1. Re: How to get manifest from war on JBoss AS
jaikiran Oct 12, 2010 8:44 AM (in response to lfryc)Would this work?
Package pack = applicationClass.getPackage(); String version = null; version = pack.getImplementationVersion(); if (version == null) { version = pack.getSpecificationVersion(); }
-
2. Re: How to get manifest from war on JBoss AS
nbelaevski Oct 12, 2010 9:39 AM (in response to lfryc)Lukas,
I have the following code in VersionBean:
private Manifest readManifest() {ProtectionDomain domain = VersionBean.class.getProtectionDomain();if (domain != null) {CodeSource codeSource = domain.getCodeSource();if (codeSource != null) {URL url = codeSource.getLocation();if (url != null) {InputStream manifestStream = null;try {manifestStream = URLToStreamHelper.urlToStream(new URL(url, JarFile.MANIFEST_NAME));return new Manifest(manifestStream);} catch (MalformedURLException e1) {//that's ok - just log in debugif (LOGGER.isDebugEnabled()) {LOGGER.debug(e1.getMessage(), e1);}} catch (IOException e) {//that's ok - just log in debugif (LOGGER.isDebugEnabled()) {LOGGER.debug(e.getMessage(), e);}} finally {if (manifestStream != null) {try {manifestStream.close();} catch (IOException e) {LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e);}}}JarInputStream jis = null;try {URLConnection urlConnection = url.openConnection();urlConnection.setUseCaches(false);if (urlConnection instanceof JarURLConnection) {JarURLConnection jarUrlConnection = (JarURLConnection) urlConnection;return jarUrlConnection.getManifest();} else {jis = new JarInputStream(urlConnection.getInputStream());return jis.getManifest();}} catch (IOException e) {LOGGER.error(MessageFormat.format("Error reading META-INF/MANIFEST.MF file: {0}", e.getMessage()), e);} finally {if (jis != null) {try {jis.close();} catch (IOException e) {LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e);}}}}}}return null;}private Manifest readManifest() { ProtectionDomain domain = VersionBean.class.getProtectionDomain(); if (domain != null) { CodeSource codeSource = domain.getCodeSource(); if (codeSource != null) { URL url = codeSource.getLocation(); if (url != null) { InputStream manifestStream = null; try { manifestStream = URLToStreamHelper.urlToStream(new URL(url, JarFile.MANIFEST_NAME)); return new Manifest(manifestStream); } catch (MalformedURLException e1) { //that's ok - just log in debug if (LOGGER.isDebugEnabled()) { LOGGER.debug(e1.getMessage(), e1); } } catch (IOException e) { //that's ok - just log in debug if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } } finally { if (manifestStream != null) { try { manifestStream.close(); } catch (IOException e) { LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e); } } } JarInputStream jis = null; try { URLConnection urlConnection = url.openConnection(); urlConnection.setUseCaches(false); if (urlConnection instanceof JarURLConnection) { JarURLConnection jarUrlConnection = (JarURLConnection) urlConnection; return jarUrlConnection.getManifest(); } else { jis = new JarInputStream(urlConnection.getInputStream()); return jis.getManifest(); } } catch (IOException e) { LOGGER.error(MessageFormat.format("Error reading META-INF/MANIFEST.MF file: {0}", e.getMessage()), e); } finally { if (jis != null) { try { jis.close(); } catch (IOException e) { LOGGER.error(MessageFormat.format("Error closing stream: {0}", e.getMessage()), e); } } } } } } return null; }
-
3. Re: How to get manifest from war on JBoss AS
lfryc Dec 6, 2010 5:10 PM (in response to jaikiran)Yes, it works in my case [1], thanks.
I didn't try Nick's solution.