ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <h...@visi.com>
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 {
            java.net.URL url = clazz.getProtectionDomain().getCodeSource().getLocation();
            String location = url.toString();
            if(location.startsWith("jar")) {
                url = ((java.net.JarURLConnection)url.openConnection()).getJarFileURL();
                location = url.toString();
            } 
            
            if(location.startsWith("file")) {
                java.io.File file = new java.io.File(url.getFile());
                return file.getAbsolutePath();
            } else {
                return url.toString();
            }
        } catch (Throwable t){
        }
        return null;
    }

Hope that helps!
    
Jake

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
java/sql/Savepoint

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>    http://www.tahitiannoni.com

NC> ---------------------------------------------------------------------
NC> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
NC> For additional commands, e-mail: user-help@ant.apache.org



-- 
Best regards,
 Jacob                            mailto:hoju@visi.com


Mime
View raw message