<?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>Rafael Liu Blog &#187; jar</title>
	<atom:link href="http://rafaelliu.net/tag/jar/feed/" rel="self" type="application/rss+xml" />
	<link>http://rafaelliu.net</link>
	<description>Café, pinguins e outras coisas</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:08:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Quick one</title>
		<link>http://rafaelliu.net/2008/05/26/quick-one/</link>
		<comments>http://rafaelliu.net/2008/05/26/quick-one/#comments</comments>
		<pubDate>Mon, 26 May 2008 19:03:28 +0000</pubDate>
		<dc:creator>rafaelliu</dc:creator>
				<category><![CDATA[Dicas]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://rafaelliu.wordpress.com/?p=12</guid>
		<description><![CDATA[This one is for all of you who (like me) keeps wasting time using commands such as find, jar and grep each time you get a classpath error: #!/bin/bash if &#91; &#34;$1&#34; = &#34;&#34; &#93;; then echo &#34;Usage: jarfind REGEXP&#34;; exit; fi &#160; for d in `find . -name '*.jar'` ; do FILES=`unzip -l $d [...]]]></description>
			<content:encoded><![CDATA[<p>This one is for all of you who (like me) keeps wasting time using commands such as find, jar and grep each time you get a classpath error:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> = <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: jarfind REGEXP&quot;</span>;
	<span style="color: #7a0874; font-weight: bold;">exit</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> d <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">'*.jar'</span><span style="color: #000000; font-weight: bold;">`</span> ; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">FILES</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">unzip</span> <span style="color: #660033;">-l</span> <span style="color: #007800;">$d</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">29</span>- <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">''</span><span style="color: #007800;">$1</span><span style="color: #ff0000;">''</span><span style="color: #000000; font-weight: bold;">`</span>;
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$FILES</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$d</span>&quot;</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">for</span> f <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #007800;">$FILES</span> ; <span style="color: #000000; font-weight: bold;">do</span>
			<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; - <span style="color: #007800;">$f</span>&quot;</span>
		<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>I&#8217;ve chose to use unzip instead of jar since it&#8217;s far more commonly seem. Move it to /usr/local/bin/jarfind  (well, that&#8217;s a little personal) and chmod it to +x.</p>
<p>I works searching all jars under the current directory for a regular expression, most commonly a simple class name. It returns the jar&#8217;s names and all corresponding class matches.</p>
<p>I&#8217;m <span style="text-decoration:underline;">not</span> a bash programmer, so it may not look that pretty to experienced bash programmers, but it looks beautiful to me, as it saves me a lot of time =). Feel free to make any comments.</p>
<p><strong>EDIT:</strong></p>
<p>first known bug: doesn&#8217;t escape special characters in paths =/</p>
]]></content:encoded>
			<wfw:commentRss>http://rafaelliu.net/2008/05/26/quick-one/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

