{"id":77528,"date":"2020-04-03T14:26:49","date_gmt":"2020-04-03T08:56:49","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=77528"},"modified":"2020-04-03T14:26:49","modified_gmt":"2020-04-03T08:56:49","slug":"java-jar-file","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/","title":{"rendered":"Java JAR File &#8211; Learn to Create your own File in Java"},"content":{"rendered":"<p>You might have sometimes downloaded some applications in your machine and you would have been asked to extract the jar file to access all the files of the application.<\/p>\n<p>This jar file is nothing but the bundle or group of multiple Java class files merged into a single archive file. Java JAR file stands for Java Archive file.<\/p>\n<p>The JAR file can store many kinds of files like images, video, or audio files. The JAR file decreases the downloading time because the JAR file is the compressed version of a normal file therefore the size is reduced.<\/p>\n<p>There should be a Java Runtime Environment in your machine to open a JAR file in Windows operating system. If it is not there, then you can also use decompression software to access the files in the JAR.<\/p>\n<p>In this article, we will learn about JAR files and how to create, view (decompress), extract, run, and update the JAR files in Java.<\/p>\n<h3>What is a JAR file in Java?<\/h3>\n<p>The basis of the JAR file format is the zip file format. A JAR file contains <em><strong>Java classes<\/strong><\/em> and other executable files. We mainly use the JAR files to implementing the libraries.<\/p>\n<p>We can organize our Java programs in Jar files. And, with the help of classpath, we can also use the existing Java code via Jar file. If you need to use the classes of JAR files in your application, you have to add the JAR file to your classpath.<\/p>\n<p>To perform basic operations related to the JAR file, we use the Java Archive Tool (JAR tool). This tool is provided by the Java Development Kit (JDK).<\/p>\n<h4>The Manifest File in Jar File<\/h4>\n<p>A manifest file is a special file that is present in the META-INF directory and named as MANIFEST.MF. The manifest file contains special meta-information to describe how to use the JAR file.<\/p>\n<p>For example, configuring a Classpath, setting the entry point, setting version information.<\/p>\n<p>We can specify our entry point by using the<strong> e<\/strong> option, and the jar command will add it to the generated manifest file.<\/p>\n<p><strong>Example to run a jar file with an entry point specified:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar cfe MyJar.jar com.techvidvan.jar.JarExample com\/techvidvan\/jar\/*.class<\/pre>\n<h4>Creating JAR Files in Java<\/h4>\n<p>To create a Jar file in Java, we use the jar command. We need to use the <strong>cf<\/strong> option where<strong> c<\/strong> indicates that we are creating a file and<strong> f<\/strong> specifies the file. The following is the syntax of writing:<\/p>\n<p><strong>JAR command:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar cf jarfilename inputfiles<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar cf MyJar.jar MyClas.class<\/pre>\n<p>This command creates a jar file <strong>MyJar.jar<\/strong><\/p>\n<h5>Creating an Executable Jar File using the Jar Tool<\/h5>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77941\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg\" alt=\"\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<p>The jar tool provides many switches, some of them are as follows:<\/p>\n<ol>\n<li><strong>-c<\/strong> creates a new jar file.<\/li>\n<li><strong>-v<\/strong> displays the included or extracted resource on the standard output (verbose output).<\/li>\n<li><strong>-m<\/strong> includes manifest information from the given manifest file.<\/li>\n<li><strong>-f<\/strong> specifies the jar filename.<\/li>\n<li><strong>-x<\/strong> extracts files from the jar file.<\/li>\n<\/ol>\n<h4>Viewing JAR Files in Java<\/h4>\n<p>We can use the <strong>tf<\/strong> command to view the contents of .jar files.<\/p>\n<p><strong>The syntax is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar tf jarfilename<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar tf MyJar.jar<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77951\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-1.png\" alt=\"\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h4>Extracting JAR Files in Java<\/h4>\n<p>We can use the jar command using <strong>xf<\/strong> which represents the extraction of a jar file.<\/p>\n<p><strong>The syntax is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar xf jarfilename<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar xf MyJar.jar<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77952\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-2.png\" alt=\"\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>The following screenshot contains a <strong>MyJarFile<\/strong> folder which is created after running the extract command:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77953\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/04\/java-jar-file-output-3.png\" alt=\"\" width=\"1079\" height=\"277\" \/><\/a><\/p>\n<h4>Updating the JAR Files in Java<\/h4>\n<p>We can use the jar command to update the contents of a jar file using <strong>uf<\/strong> where u indicates update and <strong>f<\/strong> indicates a file.<\/p>\n<p><strong>The syntax is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar uf jarfilename inputfile(s)\n<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar uf MyJar.jar<\/pre>\n<h4>Running a JAR file in Java<\/h4>\n<p>To run a jar file we use the java command.<\/p>\n<p><strong>The syntax is:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">java -jar jarfilename<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">java -jar MyJar.jar<\/pre>\n<h4>Verbose Output<\/h4>\n<p>To get a verbose output we can have more information out of the jar command. For this, we can simply add the v option for verbose.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">jar cvfm MyJar.jar inputfile\n<\/pre>\n<h3>Summary<\/h3>\n<p>The Jar file is used to aggregate or collect many class files, audio files, image files, or directories into a single file. In this article, we learned to create, view, extract, update, and run JAR files in Java.<\/p>\n<p>We also discussed the manifest file Java that stores a meta-information about the jar files.<\/p>\n<p>That was all for Java JAR Files. Thank you for reading our article. Do share your feedback through the comment section below.<\/p>\n<p>Happy Learning \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might have sometimes downloaded some applications in your machine and you would have been asked to extract the jar file to access all the files of the application. This jar file is nothing&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":77941,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2188,2189,2190,2191,2192,2193,2194,2195,2196],"class_list":["post-77528","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-create-a-jar-file-in-java","tag-extracting-a-jar-file","tag-jar-file-in-java","tag-jar-file-in-java-with-example","tag-java-jar-file","tag-running-a-jar-file-in-java","tag-updating-a-jar-file-in-java","tag-verbose-output","tag-viewing-a-jar-file"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java JAR File - Learn to Create your own File in Java - TechVidvan<\/title>\n<meta name=\"description\" content=\"Make yourself aware with the concept of Java JAR File with some examples. And Explore how to create, view, extract, run, update a JAR File in Java.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java JAR File - Learn to Create your own File in Java - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Make yourself aware with the concept of Java JAR File with some examples. And Explore how to create, view, extract, run, update a JAR File in Java.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-03T08:56:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java JAR File - Learn to Create your own File in Java - TechVidvan","description":"Make yourself aware with the concept of Java JAR File with some examples. And Explore how to create, view, extract, run, update a JAR File in Java.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/","og_locale":"en_US","og_type":"article","og_title":"Java JAR File - Learn to Create your own File in Java - TechVidvan","og_description":"Make yourself aware with the concept of Java JAR File with some examples. And Explore how to create, view, extract, run, update a JAR File in Java.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-04-03T08:56:49+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java JAR File &#8211; Learn to Create your own File in Java","datePublished":"2020-04-03T08:56:49+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/"},"wordCount":711,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg","keywords":["Create a JAR file in Java","Extracting a JAR File","JAR file in Java","Jar File in Java with Example","Java JAR file","Running a JAR file in Java","Updating a JAR File in Java","Verbose Output","Viewing a JAR File"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/","url":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/","name":"Java JAR File - Learn to Create your own File in Java - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg","datePublished":"2020-04-03T08:56:49+00:00","description":"Make yourself aware with the concept of Java JAR File with some examples. And Explore how to create, view, extract, run, update a JAR File in Java.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-jar-file\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/04\/how-to-create-a-JAR-file-in-java.jpg","width":802,"height":420,"caption":"create a jar file in java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-jar-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java JAR File &#8211; Learn to Create your own File in Java"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=77528"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/77528\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/77941"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=77528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=77528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=77528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}