<?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; runnable jar</title>
	<atom:link href="http://garyboone.com/tag/runnable-jar/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>
		<item>
		<title>Creating Single-file Runnable Jars in Scala with eclipse</title>
		<link>http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-eclipse/</link>
		<comments>http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-eclipse/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 06:47:02 +0000</pubDate>
		<dc:creator>gary</dc:creator>
				<category><![CDATA[Scala]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[runnable jar]]></category>

		<guid isPermaLink="false">http://garyboone.com/2009/06/creating-single-file-runnable-jars-in-scala-and-eclipse/</guid>
		<description><![CDATA[How do you create a single runnable jar that contains all the files it needs to run? This is one of those questions that should be easier to answer. Here&#8217;s how to do it in eclipse and NetBeans.
First, eclipse, following the post here:1. Create a Java class to run your Scala main:

package scala.loader;
import java.util.*;
public class [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">How do you create a single runnable jar that contains all the files it needs to run? This is one of those questions that should be easier to answer. Here&#8217;s how to do it in eclipse and NetBeans.</p>
<p style="clear: both">First, eclipse, following the post <a href="http://www.artima.com/forums/flat.jsp?forum=282&#038;thread=245933">here</a>:<br />1. Create a Java class to run your Scala main:</p>
<pre class="brush: java;">
package scala.loader;
import java.util.*;
public class ScalaEntryPoint
{
    public static void main(String[] args) {
    List&lt;string&gt; argList = new ArrayList&lt;string&gt;();
    argList.add(&quot;YourScalaObjectWithMain&quot;);
    for (String s : args) argList.add(s);
        scala.tools.nsc.MainGenericRunner.main(argList.toArray(new String[0]));
    }
}
</pre>
<p style="clear: both">Be sure to change <em>YourScalaObjectWithMain</em> to your class. Also, you&#8217;ll have to add the Scala tools jar to your projects classpath: <em>Project</em> | <em>Properties</em> | <em>Java Build Path</em> tab | <em>Libraries</em> tab | <em>Add External Jars&#8230;</em> button. Then pick the <em>scala.tools.nsc</em> file in your eclipse/plugins folder.</p>
<p>2. Create a Run Configuration to run the Java class. Check that it runs.</p>
<p style="clear: both">3. Then choose <em>File</em> | <em>Export&#8230;,</em> then <em>Java</em> | <em>Runnable JAR File</em>, then pick the Java run configuration to export and a destination. Optionally, you can save the ant XML file that does the export. Later, after some edits, you can rejar using</p>
<blockquote style="clear: both"><p>ant -f yourjarXMLfile.xml</p>
</blockquote>
<p style="clear: both">If you change your libraries, be sure to repeat the complete Export process to make sure your jar scrips includes the correct jars.</p>
<p style="clear: both">
<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-eclipse/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
