<?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/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Frank Carver&#039;s Punch Barrel &#187; ant</title>
	<atom:link href="http://blog.punchbarrel.com/tag/ant/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.punchbarrel.com</link>
	<description>Frank Carver&#039;s musings about software and life</description>
	<lastBuildDate>Thu, 08 Dec 2011 22:58:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<copyright>Copyright &#xA9; Frank Carver&#039;s Punch Barrel 2010 </copyright>
	<managingEditor>frank.carver@googlemail.com (Frank Carver&#039;s Punch Barrel)</managingEditor>
	<webMaster>frank.carver@googlemail.com (Frank Carver&#039;s Punch Barrel)</webMaster>
	<ttl>1440</ttl>
	<image>
		<url>http://punchbarrel.com/images/punchbarrel-144.jpg</url>
		<title>Frank Carver&#039;s Punch Barrel</title>
		<link>http://blog.punchbarrel.com</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>Frank Carver&#039;s musings about software and life</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &#38; Culture" />
	<itunes:author>Frank Carver&#039;s Punch Barrel</itunes:author>
	<itunes:owner>
		<itunes:name>Frank Carver&#039;s Punch Barrel</itunes:name>
		<itunes:email>frank.carver@googlemail.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://punchbarrel.com/images/punchbarrel-144.jpg" />
		<item>
		<title>Build and deployment scripts using &#8220;real&#8221; programming languages</title>
		<link>http://blog.punchbarrel.com/2009/03/08/build-and-deployment-scripts-using-real-programming-languages/</link>
		<comments>http://blog.punchbarrel.com/2009/03/08/build-and-deployment-scripts-using-real-programming-languages/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 20:46:19 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[deploy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[vlad]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=1215</guid>
		<description><![CDATA[Like many teams, I&#8217;m sure, we are trying to squeeze every drop of effectiveness out of our time. Manual build and deployment not only takes up valuable time, but also acts as a drag on the development process. Anything which pulls developers out of &#8220;the zone&#8221; is a bad thing for productivity. We usually use [...]]]></description>
			<content:encoded><![CDATA[<p>Like many teams, I&#8217;m sure, we are trying to squeeze every drop of effectiveness out of our time. Manual build and deployment not only takes up valuable time, but also acts as a drag on the development process. Anything which pulls developers out of &#8220;the zone&#8221; is a bad thing for productivity.</p>
<p>We usually use the familiar &#8220;<a href="http://ant.apache.org/">ant</a>&#8221; build tool for building deployable artefacts, but have found it increasingly fiddly as our expectations have grown. And ant is hardly useful at all for real-world deployment tasks.</p>
<p>It may be the time to re-consider other build and deployment options.</p>
<p><a href="http://alex-verkhovsky.blogspot.com/2009/03/lets-use-real-languages-for-builds.html">Thread.current.to_s: Let&#8217;s use real languages for builds</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2009/03/08/build-and-deployment-scripts-using-real-programming-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>building an executable jar from other jars</title>
		<link>http://blog.punchbarrel.com/2008/10/22/building-an-executable-jar-from-other-jars/</link>
		<comments>http://blog.punchbarrel.com/2008/10/22/building-an-executable-jar-from-other-jars/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 14:59:36 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[classloader]]></category>
		<category><![CDATA[executable]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[one-jar]]></category>
		<category><![CDATA[pack]]></category>
		<category><![CDATA[taskdef]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=707</guid>
		<description><![CDATA[I started the day cursing the stupid jar format, but ended the day smiling. I needed to build a stand-alone executable jar which accessed a MySQL database but kept getting all sorts of build-time and run-time errors. Normally to make an executable jar I use the excellent pack ant task which build a minimal jar [...]]]></description>
			<content:encoded><![CDATA[<p>I started the day cursing the stupid jar format, but ended the day smiling. I needed to build a stand-alone executable jar which accessed a MySQL database but kept getting all sorts of build-time and run-time errors.</p>
<p>Normally to make an executable jar I use the excellent <a href="http://sadun-util.sourceforge.net/pack.html">pack</a> ant task which build a minimal jar file by trawling all the class dependencies in yout code and including just the required classes from the classpath.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><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;jar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pack&quot;</span> </span>
<span style="color: #009900;">      <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;org.sadun.util.ant.Pack&quot;</span> <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;lib/pack.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pack</span> </span>
<span style="color: #009900;">       classes = <span style="color: #ff0000;">&quot;${root.classes}&quot;</span></span>
<span style="color: #009900;">       targetJar = <span style="color: #ff0000;">&quot;dist/${project.name}.jar&quot;</span></span>
<span style="color: #009900;">       manifestMainClass = <span style="color: #ff0000;">&quot;${main.class}&quot;</span></span>
<span style="color: #009900;">       excludePkg = <span style="color: #ff0000;">&quot;java,sun&quot;</span></span>
<span style="color: #009900;">       includePkg = <span style="color: #ff0000;">&quot;com,org,javax&quot;</span></span>
<span style="color: #009900;">   <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpath</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;classpath&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pack<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Just set up the main.class property to the main class of the application, and set the root.classes property to a class which refers to everything you need (in many cases this will be the same main class) and you get a lovely small executable jar.</p>
<p>However, trying this approach with MySQL cause a bunch of problems. First I needed to add a load of (apparently dynamically loaded) MySQL class names such as <code>com.mysql.jdbc.Driver</code>.</p>
<p>I thought I was doing well when I had resolved that issue, but then I hit an even harder problem:</p>
<p><tt>java.lang.RuntimeException: Can't load resource bundle due to underlying exception<br />
java.util.MissingResourceException: Can't find bundle for base name com.mysql.jdbc.LocalizedErrorMessages, locale en_GB</tt></p>
<p>Despite spending an hour or so searching and trying, I could not convince pack to find it. So I had to look elsewhere.</p>
<p>The solution I eventually chose was &#8220;one-jar&#8221; &#8211; a trick which subverts the normal jar execution process and creates a custom classloader to resolve jars within a jar.  I still use pack to minimise the amount of other classes included in my project, but explicitly include the whole MySQL driver jar.</p>
<p>My ant target now looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><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;jar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;pack&quot;</span> </span>
<span style="color: #009900;">      <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;org.sadun.util.ant.Pack&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;lib/pack.jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pack</span> </span>
<span style="color: #009900;">       classes = <span style="color: #ff0000;">&quot;${root.classes}&quot;</span></span>
<span style="color: #009900;">       targetJar = <span style="color: #ff0000;">&quot;tmp/main.jar&quot;</span></span>
<span style="color: #009900;">       manifestMainClass = <span style="color: #ff0000;">&quot;${main.class}&quot;</span></span>
<span style="color: #009900;">       excludePkg = <span style="color: #ff0000;">&quot;java,sun&quot;</span></span>
<span style="color: #009900;">       includePkg = <span style="color: #ff0000;">&quot;com,org,javax&quot;</span></span>
<span style="color: #009900;">   <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;classpath</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;classpath&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pack<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;one-jar&quot;</span> </span>
<span style="color: #009900;">      <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;com.simontuffs.onejar.ant.OneJarTask&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;lib/one-jar-ant-task-0.96.jar&quot;</span> <span style="color: #000066;">onerror</span>=<span style="color: #ff0000;">&quot;report&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;one-jar</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;dist/${project.name}.jar&quot;</span> <span style="color: #000066;">manifest</span>=<span style="color: #ff0000;">&quot;src/main/files/${project.name}.mf&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;main</span> <span style="color: #000066;">jar</span>=<span style="color: #ff0000;">&quot;tmp/main.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;lib/mysql-connector-java-5.0.4-bin.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/one-jar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This builds all of my application except the MySQL bits using pack into a temporary &#8220;main.jar&#8221;, then uses one-jar to build another jar which refers to both main.jar and the MySQL driver jar.</p>
<p>I did need to create an explicit manifest file this way (usually, pack is smart enough to make it for me)</p>
<pre>
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: org.example.project.Main
</pre>
<p>I now have a working stand-alone executable jar which can access a MySQL database. Cool.</p>
<p>Read more at <a href="http://one-jar.sourceforge.net/index.php?page=introduction&#038;file=intro">Deliver Your Java Application in One-JAR™ !</a> and <a href="http://www.technowledgebase.com/2007/07/10/java-using-one-jar/">Java: Using ONE-JAR</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/10/22/building-an-executable-jar-from-other-jars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.548 seconds -->

