<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>www.jugpadova.it: Tag classloader</title>
    <link>http://www.jugpadova.it/articles/tag/classloader</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Java User Group [Padova]</description>
    <item>
      <title>From which Jar a Class was loaded?</title>
      <description>&lt;p&gt;Sometimes in production environments I face problems never encountered during development&amp;#8230; It&amp;#8217;s a general thing.. could happen with jdbc drivers or xml parsers.&lt;/p&gt;

&lt;p&gt;I just feel classes are loaded from a different jar than expected. &lt;/p&gt;

&lt;p&gt;This of course could happen if you&amp;#8217;re deploying  to a very different application server or if you&amp;#8217;ve no control over the production server classpath.&lt;/p&gt;

&lt;p&gt;I found in &lt;em&gt;javaalmanac.com&lt;/em&gt; a code snippet that can help you identify which is the jar containing a specific Class at runtime:&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_java "&gt;Class cls = MyFoo.class;
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation(); 
System.out.println(loc); 
// prints something like &amp;quot;c:/jars/MyFoo.jar&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This way you can check if your class is loaded right from the expected jar, not elsewhere :-).&lt;/p&gt;

&lt;p&gt;This has shown to be really useful during my sad production debug sessions.&lt;/p&gt;

&lt;p&gt;Hope it can help you as well.&lt;/p&gt;
</description>
      <pubDate>Sun, 13 Nov 2005 09:11:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:cc3420bb-67a5-4898-89fd-db03a11d4cd8</guid>
      <author>Paolo Dona'</author>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded</link>
      <category>class</category>
      <category>classloader</category>
      <category>jar</category>
      <category>java</category>
    </item>
  </channel>
</rss>
