<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: HOW TO:  Bootstrap Java programs in isolated classloaders</title>
	<atom:link href="http://blog.markturansky.com/archives/21/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.markturansky.com/archives/21</link>
	<description>software architecture &#38; engineering, code hints, sometimes philosophy, photography, life, etc.</description>
	<lastBuildDate>Sun, 20 Jun 2010 07:51:38 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ronald Kurr</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-1261</link>
		<dc:creator>Ronald Kurr</dc:creator>
		<pubDate>Sat, 19 Dec 2009 17:16:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-1261</guid>
		<description>Mark, I found your post interesting and thought provoking.  Although many Java applications are web-based and run inside a servlet container, I&#039;ve also seen the need for standalone headless Spring-based apps.  The ability to simplify the launching program&#039;s classpath is worth the price of admission alone.  Moving the burden of creating a proper classpath from the installer into the application itself minimizes certain types of errors -- &quot;I swear didn&#039;t touch anything.  Well, I did make a minor tweek to the launch script but what harm could that do?&quot;  Kudos.</description>
		<content:encoded><![CDATA[<p>Mark, I found your post interesting and thought provoking.  Although many Java applications are web-based and run inside a servlet container, I&#8217;ve also seen the need for standalone headless Spring-based apps.  The ability to simplify the launching program&#8217;s classpath is worth the price of admission alone.  Moving the burden of creating a proper classpath from the installer into the application itself minimizes certain types of errors &#8212; &#8220;I swear didn&#8217;t touch anything.  Well, I did make a minor tweek to the launch script but what harm could that do?&#8221;  Kudos.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Booting - Bootstrapping, Self-hosting, Self-interpreter &#171; CK Wong&#8217;s Microscopic Universe</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-755</link>
		<dc:creator>Booting - Bootstrapping, Self-hosting, Self-interpreter &#171; CK Wong&#8217;s Microscopic Universe</dc:creator>
		<pubDate>Wed, 11 Jun 2008 10:22:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-755</guid>
		<description>[...] HOW TO: Bootstrap Java programs in isolated classloaders [...]</description>
		<content:encoded><![CDATA[<p>[...] HOW TO: Bootstrap Java programs in isolated classloaders [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; You can&#8217;t keep a good idea down</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-708</link>
		<dc:creator>&#187; You can&#8217;t keep a good idea down</dc:creator>
		<pubDate>Fri, 02 May 2008 03:28:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-708</guid>
		<description>[...] deploy applications to our bus over the network by the way of a simple little bootstrap loader. You&#8217;ll note the Java class I used in my blog article uses a URLClassLoader. My example used [...]</description>
		<content:encoded><![CDATA[<p>[...] deploy applications to our bus over the network by the way of a simple little bootstrap loader. You&#8217;ll note the Java class I used in my blog article uses a URLClassLoader. My example used [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-706</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Wed, 30 Apr 2008 15:42:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-706</guid>
		<description>Hi Mark:  

How could we modify the above bootstrap program to load multiple apps?  Should we run each app within a seperate thread?

Great Article btw :D</description>
		<content:encoded><![CDATA[<p>Hi Mark:  </p>
<p>How could we modify the above bootstrap program to load multiple apps?  Should we run each app within a seperate thread?</p>
<p>Great Article btw <img src='http://blog.markturansky.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Turansky</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-645</link>
		<dc:creator>Mark Turansky</dc:creator>
		<pubDate>Tue, 01 Apr 2008 14:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-645</guid>
		<description>@scm,

Whenever you start the JVM with a &quot;-cp&quot; argument, all those jars and libs on your classpath are on the system classpath.  Any code you run in that JVM will have those libs in their classloader.

When you&#039;re writing middleware or some kind of container, you&#039;ll run into a problem where your container might need one version of a library but the application you want to deploy has the same library but a different version.  You need bootstrapping to reconcile this.  The code example I gave shows how you would set the system classloader (which is empty, because you&#039;re bootstrapping) as the parent classloader to the application you want to deploy.  This leaves the application free of your container&#039;s dependencies.

I hope that helps.  All this stuff becomes a lot clearer when you write a server that deploys other apps within it.  Most people probably never do that, but we did when we wrote our message bus (http://blog.markturansky.com/archives/26)

Mark</description>
		<content:encoded><![CDATA[<p>@scm,</p>
<p>Whenever you start the JVM with a &#8220;-cp&#8221; argument, all those jars and libs on your classpath are on the system classpath.  Any code you run in that JVM will have those libs in their classloader.</p>
<p>When you&#8217;re writing middleware or some kind of container, you&#8217;ll run into a problem where your container might need one version of a library but the application you want to deploy has the same library but a different version.  You need bootstrapping to reconcile this.  The code example I gave shows how you would set the system classloader (which is empty, because you&#8217;re bootstrapping) as the parent classloader to the application you want to deploy.  This leaves the application free of your container&#8217;s dependencies.</p>
<p>I hope that helps.  All this stuff becomes a lot clearer when you write a server that deploys other apps within it.  Most people probably never do that, but we did when we wrote our message bus (<a href="http://blog.markturansky.com/archives/26" rel="nofollow">http://blog.markturansky.com/archives/26</a>)</p>
<p>Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scm</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-640</link>
		<dc:creator>scm</dc:creator>
		<pubDate>Tue, 01 Apr 2008 00:52:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-640</guid>
		<description>Hi, what do you mean by an &quot;unpolluted system classpath&quot;?</description>
		<content:encoded><![CDATA[<p>Hi, what do you mean by an &#8220;unpolluted system classpath&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; No one should work alone. Ever.</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-565</link>
		<dc:creator>&#187; No one should work alone. Ever.</dc:creator>
		<pubDate>Wed, 26 Mar 2008 02:07:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-565</guid>
		<description>[...] and deployment them as separate components on our message bus. All our components are deployed in isolated classloaders, which will solve their problem. The older issue involved the constant instantiation/initialization [...]</description>
		<content:encoded><![CDATA[<p>[...] and deployment them as separate components on our message bus. All our components are deployed in isolated classloaders, which will solve their problem. The older issue involved the constant instantiation/initialization [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Bohm</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-348</link>
		<dc:creator>Christian Bohm</dc:creator>
		<pubDate>Fri, 07 Mar 2008 18:16:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-348</guid>
		<description>Hi guys! Nice trick.
My question is.... will this work in a swing application?
I mean... I have a swing application that calls to another swing application using the main method.
I want the caller application be in a separated classloader than the invoked one.
The problem is that the current Thread is the swing thread so if I modify swing thread&#039;s classloader, it will be modified for both applications. Right?</description>
		<content:encoded><![CDATA[<p>Hi guys! Nice trick.<br />
My question is&#8230;. will this work in a swing application?<br />
I mean&#8230; I have a swing application that calls to another swing application using the main method.<br />
I want the caller application be in a separated classloader than the invoked one.<br />
The problem is that the current Thread is the swing thread so if I modify swing thread&#8217;s classloader, it will be modified for both applications. Right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Turansky</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-59</link>
		<dc:creator>Mark Turansky</dc:creator>
		<pubDate>Tue, 29 Jan 2008 09:16:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-59</guid>
		<description>This was just an example program to learn from.  I presume that people reading this HOW TO would understand to set their HOME variable from the outside.  Maybe they&#039;d use a command line argument to their bootstrapper, maybe a -D system property.  Either way, you could then use an environment-specific path that&#039;s appropriate for your deployment without string concatentation or File.separatorChar.</description>
		<content:encoded><![CDATA[<p>This was just an example program to learn from.  I presume that people reading this HOW TO would understand to set their HOME variable from the outside.  Maybe they&#8217;d use a command line argument to their bootstrapper, maybe a -D system property.  Either way, you could then use an environment-specific path that&#8217;s appropriate for your deployment without string concatentation or File.separatorChar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skanga</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-58</link>
		<dc:creator>skanga</dc:creator>
		<pubDate>Tue, 29 Jan 2008 06:32:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-58</guid>
		<description>I always hate seeing hard coded unix filename conventions in Java code. Using  File.separatorChar is a much better idea.</description>
		<content:encoded><![CDATA[<p>I always hate seeing hard coded unix filename conventions in Java code. Using  File.separatorChar is a much better idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; Terracotta Server as a Message Bus</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-35</link>
		<dc:creator>&#187; Terracotta Server as a Message Bus</dc:creator>
		<pubDate>Sat, 26 Jan 2008 02:48:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-35</guid>
		<description>[...] way to cluster standalone Spring apps. The named classloader did the trick for us. You will need to bootstrap your application to make this work. You should probably be doing this [...]</description>
		<content:encoded><![CDATA[<p>[...] way to cluster standalone Spring apps. The named classloader did the trick for us. You will need to bootstrap your application to make this work. You should probably be doing this [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Casper</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-16</link>
		<dc:creator>Casper</dc:creator>
		<pubDate>Wed, 23 Jan 2008 01:13:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-16</guid>
		<description>Hello Mark,

I gave it another shot, motivated by this blog entry. It poses a few problems though, the JNLPClassLoader is package private in com.sun.jnlp namespace and hence completely inaccessable. But by casting to an URLClassLoader, the remote CLASSES (in fact, works for non-jws execution too) can be fetched and passed along to the new ClassLoader instance.

            URLClassLoader jnlpClassLoader = (URLClassLoader)this.getClass().getClassLoader();
            ClassLoader bootstrapClassLoader = new URLClassLoader( jnlpClassLoader.getURLs());

...and that works, but causes issues with the security manager later on. Another approach:

            URLClassLoader jnlpClassLoader = (URLClassLoader)this.getClass().getClassLoader();
            URLClassLoader classLoader = URLClassLoader.newInstance( jnlpClassLoader .getURLs(), jnlpClassLoader);

...seems to get slightly further, but causing errors on the EDT. I feel I&#039;m getting close, but I am not sure how to attempt this off the EDT or possibly simply empty the EDT first. Now I remember why I am no fan of classloaders! :D

/Casper</description>
		<content:encoded><![CDATA[<p>Hello Mark,</p>
<p>I gave it another shot, motivated by this blog entry. It poses a few problems though, the JNLPClassLoader is package private in com.sun.jnlp namespace and hence completely inaccessable. But by casting to an URLClassLoader, the remote CLASSES (in fact, works for non-jws execution too) can be fetched and passed along to the new ClassLoader instance.</p>
<p>            URLClassLoader jnlpClassLoader = (URLClassLoader)this.getClass().getClassLoader();<br />
            ClassLoader bootstrapClassLoader = new URLClassLoader( jnlpClassLoader.getURLs());</p>
<p>&#8230;and that works, but causes issues with the security manager later on. Another approach:</p>
<p>            URLClassLoader jnlpClassLoader = (URLClassLoader)this.getClass().getClassLoader();<br />
            URLClassLoader classLoader = URLClassLoader.newInstance( jnlpClassLoader .getURLs(), jnlpClassLoader);</p>
<p>&#8230;seems to get slightly further, but causing errors on the EDT. I feel I&#8217;m getting close, but I am not sure how to attempt this off the EDT or possibly simply empty the EDT first. Now I remember why I am no fan of classloaders! <img src='http://blog.markturansky.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>/Casper</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Turansky</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-15</link>
		<dc:creator>Mark Turansky</dc:creator>
		<pubDate>Tue, 22 Jan 2008 21:10:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-15</guid>
		<description>Casper,

Thanks for the inquiry.  Short answer, I don&#039;t know.

I&#039;m unfamiliar with Web Start.  I don&#039;t know how to bootstrap in that scenario.

I work mostly with web applications and back-end systems (messaging/integration).  I know we can boostrap Jetty as part of our system as well as all the disparate components deployed around the network.

I hope the code I posted can help you figure out how to bootstrap a Web Start app.  If you figure it out, please post the solution online!  I&#039;d love to see it.

Mark</description>
		<content:encoded><![CDATA[<p>Casper,</p>
<p>Thanks for the inquiry.  Short answer, I don&#8217;t know.</p>
<p>I&#8217;m unfamiliar with Web Start.  I don&#8217;t know how to bootstrap in that scenario.</p>
<p>I work mostly with web applications and back-end systems (messaging/integration).  I know we can boostrap Jetty as part of our system as well as all the disparate components deployed around the network.</p>
<p>I hope the code I posted can help you figure out how to bootstrap a Web Start app.  If you figure it out, please post the solution online!  I&#8217;d love to see it.</p>
<p>Mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Casper</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-14</link>
		<dc:creator>Casper</dc:creator>
		<pubDate>Tue, 22 Jan 2008 21:04:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-14</guid>
		<description>I used a similar approach to make a JSR-296 app restartable (for changing language), but it did not seem to work in a Web Start scenario so I gave up on that. Will this work in such an environment?</description>
		<content:encoded><![CDATA[<p>I used a similar approach to make a JSR-296 app restartable (for changing language), but it did not seem to work in a Web Start scenario so I gave up on that. Will this work in such an environment?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Turansky</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-9</link>
		<dc:creator>Mark Turansky</dc:creator>
		<pubDate>Sun, 20 Jan 2008 07:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-9</guid>
		<description>It&#039;s funny &#039;cause it&#039;s true!  Nice catch, Dan.

The above code works just fine except that you *will* want to add this single line before you reflectively invoke the &lt;code&gt;main&lt;/code&gt; method:

&lt;code&gt;
Thread.currentThread().setContextClassLoader(classloader);
&lt;/code&gt;

Lots of well-written Java software use the thread&#039;s context classloader to resolve classes and classpath-based resources.  This is a very effective way to avoid crossing the streams between classloaders.

&lt;a href=&quot;http://commons.apache.org/logging/&quot; rel=&quot;nofollow&quot;&gt;Other  software packages&lt;/a&gt; don&#039;t always play as nicely with classloaders, even when you set the context classloader.  Bootstrapping helps in this case, but well-behaved software would be even better.

FYI: Dan is one hell of a smart developer, groks all the bootstrapping and classloading challenges you&#039;re likely to face, and -- best of all -- works for me on whatever madness our bosses let us pursue :)</description>
		<content:encoded><![CDATA[<p>It&#8217;s funny &#8217;cause it&#8217;s true!  Nice catch, Dan.</p>
<p>The above code works just fine except that you *will* want to add this single line before you reflectively invoke the <code>main</code> method:</p>
<p><code><br />
Thread.currentThread().setContextClassLoader(classloader);<br />
</code></p>
<p>Lots of well-written Java software use the thread&#8217;s context classloader to resolve classes and classpath-based resources.  This is a very effective way to avoid crossing the streams between classloaders.</p>
<p><a href="http://commons.apache.org/logging/" rel="nofollow">Other  software packages</a> don&#8217;t always play as nicely with classloaders, even when you set the context classloader.  Bootstrapping helps in this case, but well-behaved software would be even better.</p>
<p>FYI: Dan is one hell of a smart developer, groks all the bootstrapping and classloading challenges you&#8217;re likely to face, and &#8212; best of all &#8212; works for me on whatever madness our bosses let us pursue <img src='http://blog.markturansky.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://blog.markturansky.com/archives/21/comment-page-1#comment-8</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sat, 19 Jan 2008 03:10:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.markturansky.com/archives/21#comment-8</guid>
		<description>You forgot to set the context classloader before the main invocation, NEWB!</description>
		<content:encoded><![CDATA[<p>You forgot to set the context classloader before the main invocation, NEWB!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
