<?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: Workaround for bug id 6753651 &#8211; find path to jar in cache under webstart</title>
	<atom:link href="http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/</link>
	<description>Software Development - random theories, code snippits and opinions</description>
	<lastBuildDate>Tue, 18 Oct 2011 23:30:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Nick</title>
		<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/comment-page-1/#comment-1374</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Thu, 06 Nov 2008 16:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/#comment-1374</guid>
		<description>Looks about right John, the getJarFilePath() should give you the path to the jar file downloaded into the webstart cache.

However it would be worth checking out David&#039;s solution above if you need the path to the jar. I haven&#039;t yet validated this myself, but in theory it uses a public API to get the same information. My solution is a rather nasty workaround to get this same info - it does work fine currently, but since it uses reflection rather than a public API it will be more prone to break in future versions of webstart/the jdk. It uses parts of the webstart library which are not public. If David&#039;s getProtectionDomain() method works it should be less likely to break in the future in this way.</description>
		<content:encoded><![CDATA[<p>Looks about right John, the getJarFilePath() should give you the path to the jar file downloaded into the webstart cache.</p>
<p>However it would be worth checking out David&#8217;s solution above if you need the path to the jar. I haven&#8217;t yet validated this myself, but in theory it uses a public API to get the same information. My solution is a rather nasty workaround to get this same info &#8211; it does work fine currently, but since it uses reflection rather than a public API it will be more prone to break in future versions of webstart/the jdk. It uses parts of the webstart library which are not public. If David&#8217;s getProtectionDomain() method works it should be less likely to break in the future in this way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/comment-page-1/#comment-1371</link>
		<dc:creator>john</dc:creator>
		<pubDate>Thu, 06 Nov 2008 10:05:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/#comment-1371</guid>
		<description>sorry I mean 
urlString=URLDecoder.decode(getJarFilePath(myUrl),”UTF8″);</description>
		<content:encoded><![CDATA[<p>sorry I mean<br />
urlString=URLDecoder.decode(getJarFilePath(myUrl),”UTF8″);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/comment-page-1/#comment-1370</link>
		<dc:creator>john</dc:creator>
		<pubDate>Thu, 06 Nov 2008 10:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/#comment-1370</guid>
		<description>Hi,
Thanks for your code, I think it can help me but I can´t see how, because I´m not an java expert.
I had
URL myUrl = this.getClass().getResource(&quot;Pant.class&quot;);
String urlString=URLDecoder.decode(myUrl.toString(),&quot;UTF8&quot;);

To replace this with your code should I use now 
URL myUrl= this.getClass().getResource(&quot;Pant.class&quot;);
String urlString=getJarFilePath(myUrl);
??

Thanks</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Thanks for your code, I think it can help me but I can´t see how, because I´m not an java expert.<br />
I had<br />
URL myUrl = this.getClass().getResource(&#8220;Pant.class&#8221;);<br />
String urlString=URLDecoder.decode(myUrl.toString(),&#8221;UTF8&#8243;);</p>
<p>To replace this with your code should I use now<br />
URL myUrl= this.getClass().getResource(&#8220;Pant.class&#8221;);<br />
String urlString=getJarFilePath(myUrl);<br />
??</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick</title>
		<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/comment-page-1/#comment-1039</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Fri, 03 Oct 2008 15:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/#comment-1039</guid>
		<description>thanks for that code David, that looks like another approach worth investigating. Does it also work with 1.6.0_07 I wonder?</description>
		<content:encoded><![CDATA[<p>thanks for that code David, that looks like another approach worth investigating. Does it also work with 1.6.0_07 I wonder?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ehrlich</title>
		<link>http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/comment-page-1/#comment-1038</link>
		<dc:creator>David Ehrlich</dc:creator>
		<pubDate>Fri, 03 Oct 2008 14:51:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.objectdefinitions.com/odblog/2008/workaround-for-bug-id-6753651-find-path-to-jar-in-cache-under-webstart/#comment-1038</guid>
		<description>While not returning exactly the same result as what you suggest, the following code seems to address the JNLP issue Sun introduced with JDK 1.5.0_16:

[cc lang=&quot;java&quot;]
    public static URL getResource(Class clazz, String name) {
        // Get the URL for the resource using the standard behavior
        URL result = clazz.getResource(name);

        // Check to see that the URL is not null and that it&#039;s a JAR URL.
        if (result != null &amp;&amp; &quot;jar&quot;.equalsIgnoreCase(result.getProtocol())) {
            // Get the URL to the &quot;clazz&quot; itself.  In a JNLP environment, the &quot;getProtectionDomain&quot; call should succeed only with properly signed JARs.
            URL classSourceLocationURL = clazz.getProtectionDomain().getCodeSource().getLocation();
            // Create a String which embeds the classSourceLocationURL in a JAR URL referencing the desired resource.
            String urlString = MessageFormat.format(&quot;jar:{0}!/{1}/{2}&quot;, classSourceLocationURL.toExternalForm(), packageNameOfClass(clazz).replaceAll(&quot;\.&quot;, &quot;/&quot;), name);

            // Check to see that new URL differs.  There&#039;s no reason to instantiate a new URL if the external forms are identical (as happens on pre-1.5.0_16 builds of the JDK).
            if (urlString.equals(result.toExternalForm()) == false) {
                // The URLs are different, try instantiating the new URL.
                try {
                    result = new URL(urlString);
                } catch (MalformedURLException malformedURLException) {
                    throw new RuntimeException(malformedURLException);
                }
            }
        }
        return result;
    }

    public static String packageNameOfClass(Class clazz) {
        String result = &quot;&quot;;
        String className = clazz.getName();
        int lastPeriod = className.lastIndexOf(&quot;.&quot;);

        if (lastPeriod &gt; -1) {
            result = className.substring(0, lastPeriod);
        }
        return result;
    }

[/cc]</description>
		<content:encoded><![CDATA[<p>While not returning exactly the same result as what you suggest, the following code seems to address the JNLP issue Sun introduced with JDK 1.5.0_16:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:735px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a> getResource<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> clazz, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the URL for the resource using the standard behavior</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a> result <span style="color: #339933;">=</span> clazz.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check to see that the URL is not null and that it's a JAR URL.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>result <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #0000ff;">&quot;jar&quot;</span>.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">getProtocol</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the URL to the &quot;clazz&quot; itself. &nbsp;In a JNLP environment, the &quot;getProtectionDomain&quot; call should succeed only with properly signed JARs.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a> classSourceLocationURL <span style="color: #339933;">=</span> clazz.<span style="color: #006633;">getProtectionDomain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCodeSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create a String which embeds the classSourceLocationURL in a JAR URL referencing the desired resource.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> urlString <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amessageformat+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MessageFormat</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jar:{0}!/{1}/{2}&quot;</span>, classSourceLocationURL.<span style="color: #006633;">toExternalForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, packageNameOfClass<span style="color: #009900;">&#40;</span>clazz<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\.</span>&quot;</span>, <span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span>, name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check to see that new URL differs. &nbsp;There's no reason to instantiate a new URL if the external forms are identical (as happens on pre-1.5.0_16 builds of the JDK).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>urlString.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>result.<span style="color: #006633;">toExternalForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The URLs are different, try instantiating the new URL.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a><span style="color: #009900;">&#40;</span>urlString<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amalformedurlexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MalformedURLException</span></a> malformedURLException<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aruntimeexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">RuntimeException</span></a><span style="color: #009900;">&#40;</span>malformedURLException<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> packageNameOfClass<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> clazz<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> result <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> className <span style="color: #339933;">=</span> clazz.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> lastPeriod <span style="color: #339933;">=</span> className.<span style="color: #006633;">lastIndexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lastPeriod <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #339933;">=</span> className.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, lastPeriod<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
	</item>
</channel>
</rss>

