<?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; executable</title>
	<atom:link href="http://blog.jayway.com/tag/executable/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>
		<item>
		<title>Executable .war with winstone-maven-plugin</title>
		<link>http://blog.jayway.com/2008/11/28/executable-war-with-winstone-maven-plugin/</link>
		<comments>http://blog.jayway.com/2008/11/28/executable-war-with-winstone-maven-plugin/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 14:37:26 +0000</pubDate>
		<dc:creator>Hugo Josefson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[executable]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[war]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=484</guid>
		<description><![CDATA[You don't need to install Tomcat, JBoss or any other web server in order to run a Java web application (.war file)! If your project is configured with a Maven pom.xml and the module has &#60;packaging&#62;war&#60;/packaging&#62;, you can just add this little piece of XML inside the pom's &#60;plugins&#62; tag: &#60;plugin&#62; &#60;groupId&#62;net.sf.alchim&#60;/groupId&#62; &#60;artifactId&#62;winstone-maven-plugin&#60;/artifactId&#62; &#60;executions&#62; &#60;execution&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>You don't need to install Tomcat, JBoss or any other web server in order to run a Java web application (.war file)!</p>
<p>If your project is configured with a Maven <code>pom.xml</code> and the module has <code>&lt;packaging&gt;war&lt;/packaging&gt;</code>, you can just add this little piece of XML inside the pom's <code>&lt;plugins&gt;</code> tag:</p>
<pre>&lt;plugin&gt;
    &lt;groupId&gt;net.sf.alchim&lt;/groupId&gt;
    &lt;artifactId&gt;winstone-maven-plugin&lt;/artifactId&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
                &lt;goal&gt;embed&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;phase&gt;package&lt;/phase&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>Then, when you run...</p>
<pre>mvn install</pre>
<p>...winstone-maven-plugin will automatically create a <code>*-standalone.jar</code> file for you, which contains your web application.</p>
<div id="attachment_501" class="wp-caption alignright" style="width: 310px"><a href="http://blog.jayway.com/wordpress/wp-content/uploads/2008/11/winstone-maven-plugin-screenshot2.png" rel="lightbox"><img class="size-medium wp-image-501" title="winstone-maven-plugin-screenshot2" src="http://blog.jayway.com/wordpress/wp-content/uploads/2008/11/winstone-maven-plugin-screenshot2-300x150.png" alt="Standalone .jar file, along with the .war file." width="300" height="150" /></a><p class="wp-caption-text">Standalone .jar file, along with the .war file.</p></div>
<p>You can run that .jar file as a standalone application, which runs your included web application on port 8080 by default:</p>
<pre>java -jar target/*-standalone.jar</pre>
<p>No web server installation necessary! No external files required! (You don't even need the .war file anymore.)</p>
<p>The resulting .jar file is actually <a href="http://winstone.sourceforge.net/">the servlet container Winstone</a>, with your .war file deployed inside it.</p>
<p>There are more configuration options on <a href="http://alchim.sourceforge.net/winstone-maven-plugin/usage.html">winstone-maven-plugin's usage page</a>.</p>
<p>I want to disable some default features of Winstone for security reasons, because they are not needed: ajp13 listener on a separate port, servlet invoker and directory listings. This is the complete plugin configuration I usually use myself:</p>
<pre>&lt;plugin&gt;
    &lt;groupId&gt;net.sf.alchim&lt;/groupId&gt;
    &lt;artifactId&gt;winstone-maven-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.2&lt;/version&gt;
    &lt;configuration&gt;
        &lt;cmdLineOptions&gt;
            &lt;property&gt;
                &lt;name&gt;httpPort&lt;/name&gt;
                &lt;value&gt;8080&lt;/value&gt;
            &lt;/property&gt;
            &lt;property&gt;
                &lt;name&gt;ajp13Port&lt;/name&gt;
                &lt;value&gt;-1&lt;/value&gt;
            &lt;/property&gt;
            &lt;property&gt;
                &lt;name&gt;controlPort&lt;/name&gt;
                &lt;value&gt;-1&lt;/value&gt;
            &lt;/property&gt;
            &lt;property&gt;
                &lt;name&gt;directoryListings&lt;/name&gt;
                &lt;value&gt;false&lt;/value&gt;
            &lt;/property&gt;
            &lt;property&gt;
                &lt;name&gt;useInvoker&lt;/name&gt;
                &lt;value&gt;false&lt;/value&gt;
            &lt;/property&gt;
        &lt;/cmdLineOptions&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;goals&gt;
                &lt;goal&gt;embed&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;phase&gt;package&lt;/phase&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;</pre>
<p>You can temporarily override these configuration parameters if you like, using command-line options when executing the standalone .jar file. Find them with <code>--help</code> when you run the .jar.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2008/11/28/executable-war-with-winstone-maven-plugin/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

