Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] Origin of a Class


  • From: rimvydas.vaidelis@xxxxxxxxxxx (Rimvydas Vaidelis)
  • Subject: [Advanced-java] Origin of a Class
  • Date: Thu, 14 Mar 2002 09:47:45 +0200

You can find the jar file from which a class was loaded in this way:

Class c =3D obj.getClass();
CodeSource source =3D c.getProtectionDomain().getCodeSource();
URL url =3D null;
if (source !=3D null)
{
=A0=A0=A0 url =3D source.getLocation();
}

The URL for the system classes will be null.

Regards,

Rimvydas
=A0
=A0

Mahesh wrote:

> If given an instance of Object, is there a way to find out the URL from=

> which it was loaded ?
>
> Object obj =3D new Object();
> You can find the classloader for this object, from
> obj.getClass().getClassLoader();
> So i can find out whether it was loaded by the system classloader or
> URLClassLoader or ...
> Can you go further than this ? Is there a way to pinpoint the jar file =
from
> which the class was loaded ?
>
> Also is there a way to find out the "classpath" through JNI ?
>
> thanks
> Mahesh
>
> _______________________________________________
> Advanced-java mailing list
> Advanced-java@xxxxxxxxxxxxxxxxxxxxxx