<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ezzatron &#187; ide</title>
	<atom:link href="http://ezzatron.com/tag/ide/feed/" rel="self" type="application/rss+xml" />
	<link>http://ezzatron.com</link>
	<description>Bringing together the fine arts of programming and death metal.</description>
	<lastBuildDate>Fri, 19 Nov 2010 06:37:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Automatically signing .jar files in NetBeans</title>
		<link>http://ezzatron.com/2009/09/29/automatically-signing-jar-files-in-netbeans/</link>
		<comments>http://ezzatron.com/2009/09/29/automatically-signing-jar-files-in-netbeans/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 09:03:41 +0000</pubDate>
		<dc:creator>Erin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[applet]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[signing]]></category>

		<guid isPermaLink="false">http://ezzatron.com/?p=143</guid>
		<description><![CDATA[Just a quick article on something I struggled to find a good example for &#8211; configuring NetBeans to sign a .jar file after compilation is complete. This is very handy, for example, when developing an applet that requires permission to access the file system. This requires the applet to be &#8220;signed&#8221; using the jarsigner utility, [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick article on something I struggled to find a good example for &#8211; configuring <strong>NetBeans </strong>to sign a .jar file after compilation is complete.</p>
<p>This is very handy, for example, when developing an <strong>applet </strong>that requires permission to access the file system. This requires the applet to be <strong>&#8220;signed&#8221;</strong> using the <strong>jarsigner </strong>utility, and this quickly becomes a tedious step when testing changes made in your applet in the browser itself.</p>
<p><span id="more-143"></span></p>
<p>I&#8217;m assuming that since you&#8217;re reading this article you have basic knowledge of <strong>Java </strong>and the <strong>keytool </strong>and <strong>jarsigner</strong> utilities. If not, there is a good introduction <a title="JAR Signing" href="http://www.cs.princeton.edu/introcs/85application/jar/sign.html">here</a>.</p>
<p>Please note that this how-to is intended for a development environment situation only. Before deploying to a production environment you should read up on the best practices and security implications of the .jar signing process.</p>
<h2>Step 1: Setting up your keystore</h2>
<p>For this step we will be using the <strong>keytool </strong>utility distributed with your <strong><acronym title="Java Development Kit">JDK</acronym></strong>. This will most likely be in the <strong>bin </strong>directory of your <strong><acronym title="Java Development Kit">JDK</acronym></strong> installation.</p>
<p>Assuming <strong>keytool </strong>is in your system path, run the command:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">keytool -genkey -alias &lt;alias name&gt; -keystore &lt;keystore path&gt; -validity 36500</div></div>
<p>Replacing <em>&lt;alias name&gt;</em> with a suitable alias, and <em>&lt;keystore path&gt;</em> with the filename you&#8217;d like for your <strong>keystore</strong>.</p>
<p>You will then be prompted for a number of inputs. For a test setup, use the following answers:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Enter keystore password: &lt;keystore password&gt; &lt;enter&gt;<br />
Re-enter new password: &lt;keystore password&gt; &lt;enter&gt;<br />
What is your first and last name?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
What is the name of your organizational unit?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
What is the name of your organization?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
What is the name of your City or Locality?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
What is the name of your State or Province?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
What is the two-letter country code for this unit?<br />
&nbsp; [Unknown]: &lt;enter&gt;<br />
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?<br />
&nbsp; [no]:  y &lt;enter&gt;<br />
<br />
Enter key password for &lt;&lt;alias name&gt;&gt;<br />
&nbsp; (RETURN if same as keystore password): &lt;key password&gt; &lt;enter&gt;</div></div>
<p>This will create a <strong>keystore</strong> file at <em>&lt;keystore path&gt;</em> which we will use in the next step to sign .jar files. Remember the passwords you used in this step as you&#8217;ll need them very soon.</p>
<p>The <em>-validity 36500</em> section simply specifies that we want this key to last for a very long time (100 years to be exact). This is fine in a <strong>development</strong> environment as you probably don&#8217;t want to have to regenerate new keys all the time, but in a <strong>production</strong> environment this would obviously be much shorter. The <em>-validity</em> value is specified in <strong>days</strong>.</p>
<h2>Step 2: Configuring your NetBeans project</h2>
<p>In this step we will be editing two configuration files from your NetBeans project; <strong>project.properties</strong> and <strong>build.xml</strong>.</p>
<p>The project.properties file should be located in the <strong>nbproject</strong> directory of your NetBeans project, and the build.xml should be in the main project folder itself.</p>
<p>You can edit these files by hand, or you can do so in <strong>NetBeans</strong> itself by switching to the <strong>Files</strong> window.</p>
<p>Add the following lines somewhere in your <strong>project.properties</strong> file, substituting the relevant paths etc. (hint: your <strong>jarsigner</strong> utility should be in the <strong>bin</strong> directory of your <strong><acronym title="Java Development Kit">JDK</acronym></strong> installation):</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jarsign.jarsigner=&lt;path to the jarsigner utility&gt;<br />
jarsign.keystore=&lt;keystore path&gt;<br />
jarsign.storepass=&lt;keystore password&gt;<br />
jarsign.keypass=&lt;key password&gt;<br />
jarsign.signedjar=&lt;path to create signed jar file at&gt;<br />
jarsign.alias=&lt;alias name&gt;</div></div>
<p>Add the following <em>inside</em> the <strong>&lt;project&gt;</strong> block in your <strong>build.xml</strong> file:</p>
<div class="codecolorer-container xml vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;-post-jar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${jarsign.jarsigner}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-keystore&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${jarsign.keystore}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-storepass ${jarsign.storepass}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-keypass ${jarsign.keypass}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-signedjar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${jarsign.signedjar}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${dist.jar}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;${jarsign.alias}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Signed Jar '${jarsign.signedjar}' created<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/echo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>And that&#8217;s it. The next time you <strong>build</strong> your project, a signed copy of the .jar file should be created automatically at the path you specified. You should also see a confirmation message in the build output.</p>
<p><strong>Enjoy!</strong></p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fezzatron.com%2F2009%2F09%2F29%2Fautomatically-signing-jar-files-in-netbeans%2F';
  addthis_title  = 'Automatically+signing+.jar+files+in+NetBeans';
  addthis_pub    = 'ezzatron';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://ezzatron.com/2009/09/29/automatically-signing-jar-files-in-netbeans/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

