<?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>Xebia Blog &#187; maven appassembler</title>
	<atom:link href="http://blog.xebia.com/tag/maven-appassembler/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +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>Maven appassembler Plugin: Dealing with Long Classpaths on Windows</title>
		<link>http://blog.xebia.com/2009/11/22/maven-appassembler-plugin-dealing-with-long-classpath-on-windows/</link>
		<comments>http://blog.xebia.com/2009/11/22/maven-appassembler-plugin-dealing-with-long-classpath-on-windows/#comments</comments>
		<pubDate>Sun, 22 Nov 2009 13:33:36 +0000</pubDate>
		<dc:creator>ShriKant Vashishtha</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[long classpath on windows]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[maven appassembler]]></category>
		<category><![CDATA[maven appassembler booter]]></category>

	<!-- AutoMeta Start -->
	<category></category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=3514</guid>
		<description><![CDATA[When it comes to generating command-line scripts for Java applications, Maven &#8220;appassembler&#8221; plugin comes handy. Its &#8220;assemble&#8221; goal does all the maven magic, i.e. searching the dependencies used for creating the Java application, adding them into the classpath of resultant script and finally copying all relevant jars to a single place. It was all working [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to generating command-line scripts for Java applications, Maven &#8220;appassembler&#8221; plugin comes handy. Its &#8220;assemble&#8221; goal does all the maven magic, i.e. searching the dependencies used for creating the Java application, adding them into the classpath of resultant script and finally copying all relevant jars to a single place. It was all working very nicely until I stumbled across the problem of long classpaths in the Windows OS.</p>
<p>Irrespective of whether you use DOS prompt or cygwin, Windows limits the length of environment variables. Though there are <a href="http://stackoverflow.com/questions/1503708/problem-running-bat-file-on-windows-due-to-input-line-is-too-long">various options</a> to overcome this problem using Java 6 wildcard classpath, mapping the path to some drive etc, they all look like workarounds to me as problem can recur again anytime.<br />
<span id="more-3514"></span></p>
<p>After some amount of research, I found appassembler plugin resolves this issue with booter-windows and booter-unix daemons. From the outset it looked like daemon does something else as the name is a bit misleading but in reality it&#8217;s a generic way to start your Java applications. The booter-unix/booter-windows platforms were introduced for the sole purpose of resolving the long classpath issue (see <a href="http://jira.codehaus.org/browse/MAPPASM-43">MAPPASM-43</a>) in appassembler maven plugin. Here&#8217;s how it looks like in the pom you are working with:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
    &lt;artifactId&gt;appassembler-maven-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;repositoryLayout&gt;flat&lt;/repositoryLayout&gt;
        &lt;installArtifacts&gt;false&lt;/installArtifacts&gt;
        &lt;target&gt;${project.build.directory}/appassembler&lt;/target&gt;
        &lt;defaultJvmSettings&gt;
            &lt;initialMemorySize&gt;512M&lt;/initialMemorySize&gt;
            &lt;maxMemorySize&gt;1024M&lt;/maxMemorySize&gt;
            &lt;extraArguments&gt;
                &lt;extraArgument&gt;-DconfigFile=../../etc/config.properties&lt;/extraArgument&gt;
                &lt;extraArgument&gt;-Dlog4j.configuration=../../etc/log4j.properties&lt;/extraArgument&gt;
            &lt;/extraArguments&gt;
        &lt;/defaultJvmSettings&gt;
        &lt;configurationDirectory&gt;etc&lt;/configurationDirectory&gt;
        &lt;daemons&gt;
            &lt;daemon&gt;
                &lt;id&gt;applicationName&lt;/id&gt;
                &lt;mainClass&gt;com.xebia.appassebler.sample.Main&lt;/mainClass&gt;
                &lt;platforms&gt;
                    &lt;platform&gt;booter-unix&lt;/platform&gt;
                    &lt;platform&gt;booter-windows&lt;/platform&gt;
                &lt;/platforms&gt;
                &lt;environmentSetupFileName&gt;app-env&lt;/environmentSetupFileName&gt;
            &lt;/daemon&gt;
        &lt;/daemons&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt; phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
                 &lt;goal&gt;generate-daemons&lt;/goal&gt;
                 &lt;goal&gt;create-repository&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>If you look at the code carefully, you&#8217;ll find &#8220;app-env&#8221; as a parameter to &#8220;environmentSetupFileName&#8221; tag. It is quite useful in passing environment variables to the resultant script. Using app-env (for UNIX) and app-env.bat (for Windows) environment setup files, I could pass a modified $REPO environment variable so that the copied repository containing dependencies is shared between booter-unix and booter-windows folders as follows:</p>
<pre>
|-- booter-unix

|   |-- bin

|   |   |-- applicationName
|   |   `-- app-env

|   `-- etc

|       `-- applicationName.xml

|-- booter-windows

|   |-- bin

|   |   |-- app-env.bat

|   |   `-- applicationName.bat

|   `-- etc

|       `-- applicationName.xml

|-- etc

|   |-- config.properties

|   `-- log4j.properties

`-- repo

    |-- &lt;dependency1&gt;.jar

    |-- &lt;dependency2&gt;.jar

    |-- ...
</pre>
<p>To copy the environment files and result of appassembler:generate-daemons maven goal to the appropriate locations we can use &#8220;maven-assembly-plugin&#8221; as follows: </p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
    &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
    &lt;configuration&gt;
        &lt;descriptor&gt;src/main/conf/descriptor.xml&lt;/descriptor&gt;
    &lt;/configuration&gt;
    &lt;executions&gt;
       &lt;execution&gt;
          &lt;goals&gt;
              &lt;goal&gt;single&lt;/goal&gt;
          &lt;/goals&gt;
          &lt;phase&gt;package&lt;/phase&gt;
       &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;
</pre>
<p>Here&#8217;s what src/main/conf/assembly.xml looks like:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;assembly&gt;
    &lt;id&gt;bin&lt;/id&gt;
    &lt;formats&gt;
        &lt;format&gt;tar.gz&lt;/format&gt;
        &lt;format&gt;zip&lt;/format&gt;
        &lt;format&gt;dir&lt;/format&gt;
    &lt;/formats&gt;
    &lt;fileSets&gt;
        &lt;fileSet&gt;
            &lt;directory&gt;target/appassembler/booter-unix&lt;/directory&gt;
            &lt;outputDirectory&gt;/booter-unix&lt;/outputDirectory&gt;
            &lt;excludes&gt;
                &lt;exclude&gt;*.bat&lt;/exclude&gt;
                &lt;exclude&gt;*.cmd&lt;/exclude&gt;
            &lt;/excludes&gt;
            &lt;lineEnding&gt;unix&lt;/lineEnding&gt;
            &lt;fileMode&gt;0744&lt;/fileMode&gt;
        &lt;/fileSet&gt;
        &lt;fileSet&gt;
            &lt;directory&gt;target/appassembler/booter-windows&lt;/directory&gt;
            &lt;outputDirectory&gt;/booter-windows&lt;/outputDirectory&gt;
        &lt;/fileSet&gt;
        &lt;fileSet&gt;
            &lt;directory&gt;target/appassembler/repo&lt;/directory&gt;
            &lt;outputDirectory&gt;/repo&lt;/outputDirectory&gt;
        &lt;/fileSet&gt;
        &lt;fileSet&gt;
            &lt;directory&gt;src/main/conf&lt;/directory&gt;
            &lt;includes&gt;
                &lt;include&gt;app-env.bat&lt;/include&gt;
            &lt;/includes&gt;
            &lt;outputDirectory&gt;/booter-windows/bin&lt;/outputDirectory&gt;
        &lt;/fileSet&gt;
        &lt;fileSet&gt;
            &lt;directory&gt;src/main/conf&lt;/directory&gt;
            &lt;includes&gt;
                &lt;include&gt;app-env&lt;/include&gt;
            &lt;/includes&gt;
            &lt;outputDirectory&gt;/booter-unix/bin&lt;/outputDirectory&gt;
            &lt;lineEnding&gt;unix&lt;/lineEnding&gt;
        &lt;/fileSet&gt;
    &lt;/fileSets&gt;
&lt;/assembly&gt;
</pre>
<p>Now, if you run &#8220;mvn clean package&#8221;, it provides you the structure as mentioned in listing 2. You can execute the script from booter-windows/bin/applicationName.bat on Windows without worrying about long classpaths now.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2009/11/22/maven-appassembler-plugin-dealing-with-long-classpath-on-windows/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2009%2F11%2F22%2Fmaven-appassembler-plugin-dealing-with-long-classpath-on-windows%2F&amp;title=Maven%20appassembler%20Plugin%3A%20Dealing%20with%20Long%20Classpaths%20on%20Windows" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2009/11/22/maven-appassembler-plugin-dealing-with-long-classpath-on-windows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/tag/maven-appassembler/feed/ ) in 0.52481 seconds, on Feb 9th, 2012 at 6:06 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 7:06 pm UTC -->
