<?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>Jayway Team Blog &#187; assembly</title>
	<atom:link href="http://blog.jayway.com/tag/assembly/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Executable .jar, with onejar-maven-plugin</title>
		<link>http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/</link>
		<comments>http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 18:00:10 +0000</pubDate>
		<dc:creator>Hugo Josefson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[executable]]></category>
		<category><![CDATA[jar]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[onejar]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=972</guid>
		<description><![CDATA[Onejar-maven-plugin collects your application including dependencies, into one executable jar. It's both easy and works well!

(UPDATED for version 1.3.0. See below.)

It lets all your dependency jars stay jars, and your code is in its own jar. All of those jars are put in a bigger jar, which is made executable.

<h4>Configuration</h4>
It may sound weird, but it's quite elegant! Just put this in your <code>pom.xml</code>'s <code>&#60;plugins&#62;</code> tag to make it work:[...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://onejar-maven-plugin.googlecode.com/">Onejar-maven-plugin</a> collects your application including dependencies, into one executable jar. It's both easy and works well!</p>
<p><strong>(UPDATED for version 1.3.0. See below.)</strong></p>
<h3>Problem</h3>
<p>If you have ever tried doing this before with Maven, you have probably used <a href="http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies">maven-assembly-plugin</a>, which would leave the door open for classpath problems!</p>
<p>It would extract all your dependency jars in one directory together with all your class files and all other classpath resources. The problem is that everything ended up in a big mix, with classpath resources possibly overwriting each other. For example, if two dependencies each had a <code>log4j.properties</code> file in their jar, one <code>log4j.properties</code> would overwrite the other.</p>
<p>No more of that mess!</p>
<h3>Solution</h3>
<p>Enter maven-onejar-plugin. It lets all your dependency jars stay jars, and your code is in its own jar. All of those jars are put in a bigger jar, which is made executable.</p>
<h4>Configuration</h4>
<p>It may sound weird, but it's quite elegant! Just put this in your <code>pom.xml</code>'s <code>&lt;plugins&gt;</code> tag to make it work:</p>
<pre>&lt;plugin&gt;
  &lt;groupId&gt;org.dstovall&lt;/groupId&gt;
  &lt;artifactId&gt;onejar-maven-plugin&lt;/artifactId&gt;
  &lt;version&gt;<strong>1.3.0</strong>&lt;/version&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;configuration&gt;
        &lt;mainClass&gt;<strong>your.package.YourMainClass</strong>&lt;/mainClass&gt;
      &lt;/configuration&gt;
      &lt;goals&gt;
        &lt;goal&gt;one-jar&lt;/goal&gt;
      &lt;/goals&gt;
    &lt;/execution&gt;
  &lt;/executions&gt;
&lt;/plugin&gt;</pre>
<p>You also need to add this to the pom:</p>
<pre>&lt;pluginRepositories&gt;
  &lt;pluginRepository&gt;
    &lt;id&gt;onejar-maven-plugin.googlecode.com&lt;/id&gt;
    &lt;url&gt;http://onejar-maven-plugin.googlecode.com/svn/mavenrepo&lt;/url&gt;
  &lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;</pre>
<p><em>Please note the new Maven repository URL. Me and onejar-maven-plugin founder Drew Stovall just recently moved the project to Google Code to make it more open and easier for others (like me!) to pitch in. <del datetime="2009-03-22T18:02:51+00:00">Yesterday, I released version 1.2.3 of onejar-maven-plugin to our new Maven repo at Google Code.</del> <strong>UPDATE: Just released version 1.3.0 with optional support for including and autoloading native libraries such as .dll files. <a href="http://onejar-maven-plugin.googlecode.com/svn/mavensite/usage.html">(detailed usage instructions.)</a></strong></p>
<p>Make sure you get the <code>&lt;pluginRepository&gt;</code> URL right so that the latest version will be available to you!</em></p>
<h4>Use</h4>
<p>Then do this to build everything:</p>
<pre>mvn install</pre>
<p>That will build both your normal jar, as well as another jar. You will get these:</p>
<div id="attachment_1152" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.jayway.com/wordpress/wp-content/uploads/2009/03/onejar-maven-plugin-screenshot.png" rel="lightbox"><img src="http://blog.jayway.com/wordpress/wp-content/uploads/2009/03/onejar-maven-plugin-screenshot-300x150.png" alt="Standalone one-jar.jar file, along with the original .jar file." title="onejar-maven-plugin-screenshot" width="300" height="150" class="size-medium wp-image-1152" /></a><p class="wp-caption-text">Standalone one-jar.jar file, along with the original .jar file.</p></div>
<p><code>myApp.one-jar.jar</code> is the big executable that includes both <code>myApp.jar</code>, and all dependency jars.</p>
<p>You can run it standalone without any extra files, like this:</p>
<pre>java -jar target/myApp.one-jar.jar</pre>
<p><em>If you found this interesting, you might find <a href="/2008/11/28/executable-war-with-winstone-maven-plugin/">my post about winstone-maven-plugin</a> enlightning as well. It shows you how to make an executable .war file.</em></p>
<h4>Credits</h4>
<p>Thank you <a href="http://dstovall.com/">Drew Stovall</a> for creating this Maven plugin in the first place, and thank you to the <a href="http://onejar-maven-plugin.googlecode.com/svn/mavensite/history.html">other contributors</a> who have also submitted patches.</p>
<p>Project homepage: <a href="http://onejar-maven-plugin.googlecode.com/">http://onejar-maven-plugin.googlecode.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/03/22/executable-jar-with-onejar-maven-plugin/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

