{"id":218,"date":"2011-04-30T15:12:51","date_gmt":"2011-04-30T20:12:51","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=218"},"modified":"2011-05-01T16:20:18","modified_gmt":"2011-05-01T21:20:18","slug":"distributing-small-java-applications","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2011\/04\/30\/distributing-small-java-applications\/","title":{"rendered":"Distributing small Java applications (i.e. convert to EXE)"},"content":{"rendered":"<p>Many times it can be said that it is not very friendly getting a .class file to run. Here is a better way to get them to run &#8211; it involves first converting it to an executable .jar and then optionally converting to an executable file on Windows.<\/p>\n<p><b>Prerequisites<\/b>:<\/p>\n<ul>\n<li>Java compiler and JRE<\/li>\n<li>It is recommended to do this procedure in a separate folder to avoid contamination and interference from other files.\n<\/ul>\n<p><b>Procedure<\/b>:<\/p>\n<ul>\n<li><b>Compile Java code<\/b> to generate hello.class (assuming hello.java in this article, replace hello with your application&#8217;s name):\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">javac hello.java<\/pre>\n<\/li>\n<li><b>Add meta file<\/b> &#8211; create file called hello.mf with the following contents (replace hello with your .java name):\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Main-Class: hello<\/pre>\n<p>Optionally, add the following line if your application depends on other jar files:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">Class-Path: (list of jar files here)<\/pre>\n<\/li>\n<li><strong>Make an executable jar<\/strong>:\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">jar cvfm *.jar hello.mf *.class<\/pre>\n<\/li>\n<li>At this point you have an executable jar which you can run with any JRE like so:\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">java -jar hello.jar<\/pre>\n<p>. But if you want to generate an EXE for Windows, continue to follow these instructions:<\/li>\n<li>Download and run <a href=\"http:\/\/launch4j.sourceforge.net\/\">Launch4J<\/a>.<\/li>\n<li>Set &#8220;jar&#8221; to hello.jar in the directory where it can be found.<\/li>\n<li>Set &#8220;output file&#8221; to hello.exe in the same directory as hello.jar.<\/li>\n<li>(Optional) Add icon by selecting icon.<\/li>\n<li>Under &#8220;Header&#8221; tab, set GUI if your Java application is GUI, otherwise select console.<\/li>\n<li>(Optional) Under &#8220;Single instance&#8221; tab, select &#8220;Allow only a single instance&#8221; if you wish to only allow one copy of your application open at the same time. Type in a random combination of letters and numbers in &#8220;mutex name&#8221; and type in your application name under &#8220;Window title&#8221;.<\/li>\n<li>Set a minimum JRE version under the &#8220;JRE&#8221; tab (such as 1.3.1).<\/li>\n<li>Save your configuration if you want to, then click the build icon at the top to build your application.<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Many times it can be said that it is not very friendly getting a .class file to run. Here is a better way to get them to run &#8211; it involves first converting it to an executable .jar and then optionally converting to an executable file on Windows. Prerequisites: Java compiler and JRE It is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/218"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=218"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/218\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}