<?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>Gary Boone, PhD &#187; NetBeans</title>
	<atom:link href="http://garyboone.com/tag/netbeans/feed/" rel="self" type="application/rss+xml" />
	<link>http://garyboone.com</link>
	<description>Clippings, code snippets, and other searchable web notes</description>
	<lastBuildDate>Mon, 21 Jun 2010 20:42:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating Single-file Runnable Jars in Scala with NetBeans</title>
		<link>http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-netbeans/</link>
		<comments>http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-netbeans/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 07:12:32 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[NetBeans]]></category>
		<category><![CDATA[runnable jar]]></category>

		<guid isPermaLink="false">http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-netbeans/</guid>
		<description><![CDATA[In NetBeans, creating a runnable jar for your Scala program is even easier. It&#8217;s done automatically when you build your project. The compile output even reminds you how to run the jar file.
The first time I did it, I saw an error about finding a Scala object. Solve that by adding the scala-library.jar to your [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">In NetBeans, creating a runnable jar for your Scala program is even easier. It&#8217;s done automatically when you build your project. The compile output even reminds you how to run the jar file.</p>
<p style="clear: both">The first time I did it, I saw an error about finding a Scala object. Solve that by adding the <em>scala-library.jar</em> to your project. Right-click on the libraries folder in the Projects tab on the left sidebar. Choose <em>Add JAR/Folder</em> and find your <em>scala-library.jar</em>. Because I installed Scala with MacPorts, mine was under </p>
<p style="clear: both">
<blockquote style="clear: both"><p>/opt/local/var/macports/software/scala/2.7.4_0/opt/local/share/scala/lib</p>
</blockquote>
<p style="clear: both">
<p style="clear: both">See <a href="http://garyboone.com/2009/06/installing-scala-on-macs-via-macports/">this blog entry</a> for more on finding MacPorts installations.</p>
<p style="clear: both">
<p style="clear: both">Add any other required libaries this way. Rebuild. Then you can run your program via</p>
<p style="clear: both">
<blockquote style="clear: both"><p>$ java -jar YourProgram</p>
</blockquote>
<p style="clear: both">
<p style="clear: both">in the <em>dist/</em> directory.</p>
<p style="clear: both">
<p style="clear: both">Note that by default, the NetBeans jar mechanism creates a jar file for your program and then adds the libraries you specified into a <em>lib</em> directory. So it&#8217;s not a single executable jar. You can then zip and distribute the jar/directory. The advantage of this approach is that you can update the libraries in the lib directory without having to rejar everything. You can probably also save space by using symbolic links in the <em>lib</em> directory to point to your jar locations. I haven&#8217;t tried that, though.</p>
<p style="clear: both">
<p style="clear: both">You can ignore the lib directory by directly linking to your libraries in the java command using Xbootclasspath. Here, I&#8217;ve added two libraries, Configgy and the Scala jar, to my project, but note that I also had to include the path to the Java SDK:</p>
<p style="clear: both">
<blockquote style="clear: both"><p> java -Xbootclasspath:/opt/local/var/macports/software/scala/2.7.4_0/opt/local/share/scala/lib/scala-library.jar:../configgy/dist/configgy-1.3/configgy-1.3.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Classes/classes.jar -jar ScalaApplication1.jar </p>
</blockquote>
<p style="clear: both">
<p style="clear: both">If you want to create a single jar with all of the required files, then add a few lines to your build.xml file. There are many varying pages on the web about this; I found these directions simplest:</p>
<p style="clear: both">
<p style="clear: both">1. Add</p>
<pre class="brush: plain;">
&lt;target name=&quot;-pre-jar&quot;&gt;
    &lt;unjar dest=&quot;${build.classes.dir}&quot; src=&quot;${file.reference.theLibraryName.jar}&quot;&gt;
&lt;/target&gt;
</pre>
<p style="clear: both">to the <em>build.xml</em> file, replacing theLibraryName with the appropriate jar filename.</p>
<p style="clear: both">2. Rebuild</p>
<p style="clear: both">
<p style="clear: both">To get the correct library filename, switch to the <em>Files</em> tab in the left sidebar and look in the <em>project.properties</em> file. Find lines that look like these:</p>
<pre class="brush: plain;">
&lt;unjar dest=&quot;${build.classes.dir}&quot; src=&quot;${file.reference.configgy-1.3.jar}&quot;/&gt;
&lt;unjar dest=&quot;${build.classes.dir}&quot; src=&quot;${file.reference.scala-library.jar}&quot;/&gt;
</pre>
<p style="clear: both">You can <em>ls -l</em> your program in the dist directory and see that it&#8217;s much larger; it now contains the libraries. The lib directory is still there, but you don&#8217;t need it anymore.</p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-netbeans/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
