{"id":1993,"date":"2011-04-14T15:12:54","date_gmt":"2011-04-14T09:42:54","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1993"},"modified":"2011-04-14T15:12:54","modified_gmt":"2011-04-14T09:42:54","slug":"create-executable-jar-file-of-classes-in-package","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/create-executable-jar-file-of-classes-in-package\/","title":{"rendered":"Create Executable jar file of classes in package"},"content":{"rendered":"<p><a title=\"Create Jar File\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/compile-and-run-java-program-in-package-from-command-line\/\" target=\"_blank\">For the source code, please refer this article.<\/a><\/p>\n<p>As per<a title=\"Compile Java program from command line\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/compile-and-run-java-program-in-package-from-command-line\/\" target=\"_blank\"> previous article<\/a>, i am considering that you have already compiled the program.<\/p>\n<p>go to the folder &#8220;classes&#8221; and create a manifest file named as &#8220;<span style=\"text-decoration: underline;\">manifest.txt<\/span>&#8221; and add the name of starting java class as shown below.<\/p>\n<blockquote><p><strong>Main-Class: com.g2.ExecJar.Start<\/strong><\/p><\/blockquote>\n<p>or, run below command in command prompt<\/p>\n<blockquote><p><strong>echo Main-Class: com.g2.ExecJar.Start &gt;manifest.txt<\/strong><\/p><\/blockquote>\n<p>now, run the command to create a jar file:<\/p>\n<blockquote><p><strong>jar cvfm First.jar manifest.txt comg2ExecJar*<\/strong><\/p><\/blockquote>\n<p><!--more--><br \/>\nWhere,<\/p>\n<ul>\n<li> &#8220;jar&#8221; is the tool provided by the jdk to create the jar file.<\/li>\n<li> &#8220;cvfm&#8221; is the argument.<a title=\"jar tool of java\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/tooldocs\/solaris\/jar.html\" target=\"_blank\"> check this documentation to know about all the arguments provided by the java<\/a>.<\/li>\n<li> &#8220;manifest.txt&#8221; name of the manifest file. (<strong>Remember file must have carriage return value or one blank line at End of document<\/strong>).<\/li>\n<li> &#8220;comg2ExecJar*&#8221; tells the tool that include all the files (*.class) in jar.<\/li>\n<\/ul>\n<p>To run the jar, in command prompt, enter command:<\/p>\n<blockquote><p><strong>java -jar First.jar<\/strong><\/p><\/blockquote>\n<p><strong>Question :Why the jar file is not executing ? it opens in winrar instead of execution.<br \/>\nAnswer : <\/strong> This problem occurs mainly after installation of the winrar. To change the program for opening jar file, run below code in batch file:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n@echo OFF\nassoc .jar=jarfile\nftype jarfile=&quot;D:RMBjdkbinjavaw.exe&quot; -jar &quot;%1&quot; %*\npause\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create Executable jar file of classes in package<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[3],"tags":[329],"class_list":["post-1993","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1984,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/compile-and-run-java-program-in-package-from-command-line\/","url_meta":{"origin":1993,"position":0},"title":"Compile and run Java program in package from command line","author":"Jitendra","date":"April 14, 2011","format":false,"excerpt":"How to Compile JAVA Program in Package from command line","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Java Directory structure","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/Java-Directory-structure.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":4165,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/generating-executable-jar-file-with-all-dependencies-and-libraries-in-single-jar-using-netbeans-and-eclipse\/","url_meta":{"origin":1993,"position":1},"title":"Generating Single Executable jar file with all dependencies and libraries using Netbeans and Eclipse","author":"Jitendra","date":"January 19, 2015","format":false,"excerpt":"Generating Single Jar file with all dependencies in Eclipse is easy. We just need to follow below steps : Either from the context menu or from the menu bar's File menu, select Export. Expand the Java node and select JAR file. Click Next. In the JAR File Specification page, select\u2026","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1643,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/servlet-hibernate-jquery-and-ajax-based-google-like-chat\/","url_meta":{"origin":1993,"position":2},"title":"Servlet, Hibernate, jQuery and Ajax based google like chat","author":"Jitendra","date":"March 14, 2011","format":false,"excerpt":"Servlet, Hibernate, jQuery and Ajax based google like chat with source code","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"Servlet, Hibernate, jQuery and Ajax based google like chat","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Servlet-Hibernate-jQuery-and-Ajax-based-google-like-chat.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1834,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/step-by-step-simple-login-application-in-struts-2\/","url_meta":{"origin":1993,"position":3},"title":"Step by Step Simple Login Application in Struts 2","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Example of Simple Login Application in Struts 2","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"Final Structure of Struts 2 login application","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Final-Structure-of-Struts-2-login-application.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1664,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/step-by-step-dwr-application-simple-ajax-in-java\/","url_meta":{"origin":1993,"position":4},"title":"Step by Step DWR Application &#8211; Simple AJAX in JAVA","author":"Jitendra","date":"March 15, 2011","format":false,"excerpt":"Step by Step DWR Application - Simple AJAX in JAVA","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"How DWR works in Java","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-DWR-works-in-Java.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1629,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/nested-class-and-its-necessity-with-example\/","url_meta":{"origin":1993,"position":5},"title":"Nested Class and its necessity with example","author":"Jitendra","date":"March 11, 2011","format":false,"excerpt":"Example and Introduction of Nested classes in JAVA and there Types","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Nested Class in JAVA","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Nested-Class-in-JAVA.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1993"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1993\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}