<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>www.jugpadova.it: From which Jar a Class was loaded?</title>
    <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded</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 -0600</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>
    <item>
      <title>"From which Jar a Class was loaded?" by Egor</title>
      <description>&lt;p&gt;You are the man! Saved my day.&lt;/p&gt;</description>
      <pubDate>Sun, 11 Jan 2009 18:39:03 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:3ced52b4-c73f-49d8-bd45-65a444f48311</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-54008</link>
    </item>
    <item>
      <title>"From which Jar a Class was loaded?" by Benoit Moussaud</title>
      <description>&lt;p&gt;Very Useful, thanks !&lt;/p&gt;</description>
      <pubDate>Fri, 04 Jan 2008 14:35:05 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:6ad65bb1-ff7a-4c73-b3ca-e1f84b173505</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-53947</link>
    </item>
    <item>
      <title>"From which Jar a Class was loaded?" by Bert</title>
      <description>&lt;p&gt;Thx, this helped.&lt;/p&gt;</description>
      <pubDate>Tue, 10 Oct 2006 18:06:44 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:47c5621e-1b9a-4cd5-9643-42b6926f13b4</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-4671</link>
    </item>
    <item>
      <title>"From which Jar a Class was loaded?" by jug-33</title>
      <description>&lt;p&gt;hi there,&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not a jug&amp;#8217;s member but this is my thought. &lt;/p&gt;

&lt;p&gt;The developer must be to know the english, because all the documentation in the world is in english language and if we want to make grow the community and to go around the world write in english , yeh yeh of course sometimes we can mistake the grammer and we could to make a shit scenarious &amp;#8230; but only the man without fear can to speak with god.&lt;/p&gt;</description>
      <pubDate>Sat, 17 Dec 2005 18:20:55 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:b805171c-1f43-49f5-98dd-688398685094</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-15</link>
    </item>
    <item>
      <title>"From which Jar a Class was loaded?" by Lucio</title>
      <description>&lt;p&gt;The forum doesn&amp;#8217;t pretend to be english.
Simply we would like all people could read contents, even english people.&lt;/p&gt;

&lt;p&gt;Write as you want, italian or english, but if the post is i english, it would be polite to comment in english.&lt;/p&gt;</description>
      <pubDate>Thu, 15 Dec 2005 18:27:27 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:a5771814-e90d-4c1d-9428-d3792c07c90a</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-14</link>
    </item>
    <item>
      <title>"From which Jar a Class was loaded?" by jug-33</title>
      <description>&lt;p&gt;Perch&amp;egrave; ci sono 4 pagine in italiano ed una inglese. &lt;/p&gt;

&lt;p&gt;I commenti li devo scrivere in Inglese o in Italiano. Per me sarebbe pi&amp;ugrave; semplice scrivere in italiano ma se mi ritrovo in un forum inglese scrivo in inglese , ma se il forum &amp;egrave; italiano e si spaccia per inglese scrivo in italiano . &lt;/p&gt;

&lt;p&gt;Insomma inglese o tutto o niente (compresi i commenti)&lt;/p&gt;</description>
      <pubDate>Tue, 13 Dec 2005 14:46:43 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:d23d6477-e0df-408b-b1d5-023fdc22e8de</guid>
      <link>http://www.jugpadova.it/articles/2005/11/13/from-which-jar-a-class-was-loaded#comment-13</link>
    </item>
  </channel>
</rss>

