{"id":1510,"date":"2016-10-03T15:59:45","date_gmt":"2016-10-03T13:59:45","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1510"},"modified":"2017-05-10T22:12:59","modified_gmt":"2017-05-10T20:12:59","slug":"java-manifest","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1510","title":{"rendered":"Java &#8211; Manifest"},"content":{"rendered":"<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#Where_is_the_manifest\"><span class=\"toc_number toc_depth_1\">1<\/span> Where is the manifest ?<\/a><\/li><li><a href=\"#How_to_fill_the_manifest_file\"><span class=\"toc_number toc_depth_1\">2<\/span> How to fill the manifest file ?<\/a><\/li><li><a href=\"#Getting_manifest\"><span class=\"toc_number toc_depth_1\">3<\/span> Getting manifest<\/a><\/li><li><a href=\"#Manifest_elements\"><span class=\"toc_number toc_depth_1\">4<\/span> Manifest elements<\/a><ul><li><a href=\"#Main_attributes\"><span class=\"toc_number toc_depth_2\">4.1<\/span> Main attributes<\/a><\/li><li><a href=\"#Entries\"><span class=\"toc_number toc_depth_2\">4.2<\/span> Entries<\/a><\/li><\/ul><\/li><\/ul><\/div>\n<h1><span id=\"Where_is_the_manifest\">Where is the manifest ?<\/span><\/h1>\n<p>By default the manifest can be found here in your artifact : &#8220;META-INF\/MANIFEST.MF&#8221;.<\/p>\n<h1><span id=\"How_to_fill_the_manifest_file\">How to fill the manifest file ?<\/span><\/h1>\n<p>The manifest file can be set :<\/p>\n<ul>\n<li>statically<\/li>\n<li>when you build your artifact<\/li>\n<\/ul>\n<p>Some plugins helps you to custom your manifest.<\/p>\n<p>For jar artifacts :<\/p>\n<pre lang=\"xml\">\r\n<build>\r\n    <plugins>\r\n      <plugin>\r\n        <groupId>org.apache.maven.plugins<\/groupId>\r\n        <artifactId>maven-jar-plugin<\/artifactId>\r\n        <version>${maven-jar-plugin.version}<\/version>\r\n        <configuration>\r\n          <archive>\r\n            <index>true<\/index>\r\n            <manifest>\r\n              <addClasspath>true<\/addClasspath>\r\n            <\/manifest>\r\n            <manifestEntries>\r\n              <mode>development<\/mode>\r\n              <url>${project.url}<\/url>\r\n              <key>value<\/key>\r\n            <\/manifestEntries>\r\n          <\/archive>\r\n        <\/configuration>\r\n      <\/plugin>\r\n    <\/plugins>\r\n  <\/build>\r\n<\/pre>\n<p>For war artifacts :<\/p>\n<pre lang=\"xml\">\r\n<build>\r\n    <plugins>\r\n      <plugin>\r\n        <groupId>org.apache.maven.plugins<\/groupId>\r\n        <artifactId>maven-war-plugin<\/artifactId>\r\n        <version>${maven-war-plugin.version}<\/version>\r\n        <configuration>\r\n          <archive>            \r\n            <manifest>\r\n              <addClasspath>true<\/addClasspath>\r\n            <\/manifest>\r\n            <manifestEntries>\r\n              <mode>development<\/mode>\r\n              <url>${project.url}<\/url>\r\n              <key>value<\/key>\r\n            <\/manifestEntries>\r\n          <\/archive>\r\n        <\/configuration>\r\n      <\/plugin>\r\n    <\/plugins>\r\n  <\/build>\r\n\r\n<\/pre>\n<h1><span id=\"Getting_manifest\">Getting manifest<\/span><\/h1>\n<pre lang=\"java\">\r\n\/\/ get manifest as input stream :\r\nInputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);\r\n\r\n\/\/ read manifest:\r\nManifest manifest = new Manifest();\r\nmanifest.read(inputStream);\r\n\r\n<\/pre>\n<h1><span id=\"Manifest_elements\">Manifest elements<\/span><\/h1>\n<h2><span id=\"Main_attributes\">Main attributes<\/span><\/h2>\n<p>To get the main Attributes for the Manifest :<\/p>\n<pre lang=\"java\">\r\nAttributes mainAttributes = manifest.getMainAttributes();\r\n\r\nfor(Object attribute : mainAttributes.keySet()) {\r\n  Attributes.Name attributeName = (Attributes.Name) attribute;\r\n  String attributeValue = mainAttributes.getValue(attributeName);\r\n}\r\n<\/pre>\n<h2><span id=\"Entries\">Entries<\/span><\/h2>\n<p>To get entires for the Manifest :<\/p>\n<pre lang=\"java\">\r\nMap<String, Attributes> entries = manifest.getEntries();\r\n\r\nfor(Object attribute : entries.keySet()) {\r\n  Attributes.Name attributeName = (Attributes.Name) attribute;\r\n  String attributeValue = entries.getValue(attributeName);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 Where is the manifest ?2 How to fill the manifest file ?3 Getting manifest4 Manifest elements4.1 Main attributes4.2 Entries Where is the manifest ? By default the manifest can be found here in your artifact : &#8220;META-INF\/MANIFEST.MF&#8221;. How to fill the manifest file ? The manifest file can be set : statically when you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1538,"menu_order":9,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1510","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1510"}],"version-history":[{"count":6,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1510\/revisions"}],"predecessor-version":[{"id":1956,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1510\/revisions\/1956"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1538"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}