ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject Re: Finding the jar file that a particular class resides in.
Date Wed, 19 Feb 2003 23:01:52 GMT
Hello Nathan,

from happyaxis.jsp in the Apache Axis project....

     * get the location of a class
     * @param out
     * @param clazz
     * @return the jar file or path where a class was found

    String getLocation(JspWriter out,
                       Class clazz) {
        try {
   url = clazz.getProtectionDomain().getCodeSource().getLocation();
            String location = url.toString();
            if(location.startsWith("jar")) {
                url = ((;
                location = url.toString();
            if(location.startsWith("file")) {
       file = new;
                return file.getAbsolutePath();
            } else {
                return url.toString();
        } catch (Throwable t){
        return null;

Hope that helps!

Wednesday, February 19, 2003, 11:19:02 AM, you wrote:

NC> I seem to remember a discussion a while back about trying to find out which jar file
a particular class resides in.

NC> I have two machines, one of which I can build a project and run a test file.  On the
other I can't build or run the compiled test class because it can't find the definition for

NC> I would like to know what jar file that file is in without having to check the many
different places and jar files in the classpath, etc.

NC> I have tried searching the mailing list archives to no avail.  I just can't seem to
get the correct combination of key words and phrases.

NC> Thanks.

NC> -- Nathan Christiansen
NC>    Tahitian Noni International

NC> ---------------------------------------------------------------------
NC> To unsubscribe, e-mail:
NC> For additional commands, e-mail:

Best regards,

View raw message