Sambhashanam
तकनीकी संभाषणम्
Navigation
  • Microsoft Technologies
  • Java Technologies
  • LAMP Technologies
  • Opensource
    • Microsoft Opensource
    • LAMP Opensource
    • Java Opensource
You are here: Home › Random Java, JEE Tips & Tricks & News › Find out location of a class file from where its loaded at runtime in Java
← What is architecture?
Compile thousands of file in Jdeveloper 11g, increase javac/compiler memory limit in Jdeveloper 11g →

Find out location of a class file from where its loaded at runtime in Java

August 5, 2011 | Filed under: Random Java, JEE Tips & Tricks & News and tagged with: class, classloader, java, Jee

Recently one of my coleague was facing issue Invalid class loader hierarchy. You have more than one version of 'org.apache.commons.logging.Log' visible, which is not allowed.

In our class path we found only one version of jar. I removed our jar from classpath it was still giving the same error. I was amazed and done System.out.println(System.getProperty("java.class.path")) which also didn’t provided anything meaningful, I was clueless where the jar was located.

Finally we come to the conclusion that some how we need to get the location of the class in question from where it was being loaded. But how? After some googling we found that following is the code to get the location of the class file
org.apache.commons.logging.Log.class.getProtectionDomain().getCodeSource().getLocation().toURI()

We removed the jar in question from server library and it worked.

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Google+ (Opens in new window)

Related

Did you like this article? Share it with your friends!

Tweet

Written by Dhananjay Jha

I am a java professional working with a software firm in Noida as "Manager - Product Engineering". I am always keen to learn and share what I have learnt. More professional details about me are available at Linked In and social details are available at facebook and Google Plus. I share my thought in maithili (my mother tongue) at बताह मैथिल and bataahmaithil

Follow me on Twitter
← What is architecture?
Compile thousands of file in Jdeveloper 11g, increase javac/compiler memory limit in Jdeveloper 11g →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Authors

  • Dhananjay Jha
  • Manish Kumar
  • Sushil Pandey

Recent Comments

  • muhammad on Mail merge in java for Microsoft Word document – Part I
  • muhammad on Mail merge in java for Microsoft Word document – Part I
  • Dhananjay Jha on Mail merge in java for Microsoft Word document and convert to PDF without iText – Part II
  • Clyde Symonette on Mail merge in java for Microsoft Word document and convert to PDF without iText – Part II
  • Dhananjay Kumar Jha on Mail merge in java for Microsoft Word document and convert to PDF without iText – Part II

Tag Cloud

.net activiti activiti-spring activiti bpmn C# change sender mail id in wordpress class classloader Conver MS Word to PDF disable user wordpress dox4j glassfish http response compression java Java Mail Merge MS Word javascript confirmation link on image jax-ws on tomcat jax-ws webservice Jee JTS junit junit-spring Link on Image with hidden URL link load spring configuration load spring configuration xml junit maven maven build Merge MS Word using Java Merge Word Document using XdocReport OOPS oracle weblogic PDF conversion using docx4j php mail function sample activiti process with human task and service task sending mail with attachment spring-orm spring framework spring hibernate spring hibernate integration spring jpa spring jpa hibernate integration tomcat jax-ws web service wordpress wordpress sender email

Looking for old post?

© 2021 Sambhashanam