Tag: classpath

  • Let’s compare how we print the class-path in Clojure and how we do it on Java.

    In Clojure:

    [sourcecode lang=”clojure”]
    (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
    [/sourcecode]

    In Java:

    [sourcecode lang=”clojure”]
    import java.net.URL;
    import java.net.URLClassLoader;

    public class PrintClasspath {
    public static void main(String[] args) {
    //Get the System Classloader
    ClassLoader sysClassLoader = ClassLoader.getSystemClassLoader();

    //Get the URLs
    URL[] urls = ((URLClassLoader)sysClassLoader).getURLs();

    for(int i=0; i< urls.length; i++)
    {
    System.out.println(urls[i].getFile());
    }
    }
    }
    [/sourcecode]

    To be fair, the output is not the same, but the effect is.