ch.elca.el4j.util.classpath
Class ClassloaderTools

java.lang.Object
  extended by ch.elca.el4j.util.classpath.ClassloaderTools

public final class ClassloaderTools
extends Object

Tool for analyzing the classpath (e.g. in maven projects). This tool allows the list of URLs to be easily retrieved: Call getClassPath(YourMainClass.class). Remark: 'mvn exec:java' uses an URLClassloader for the main class and passes all project dependencies plus the target directories as URLs to that.

Author:
David Bernhard (DBD)
File-location:
ClassloaderTools
Last check-in date:
2009-12-01 10:59:54 +0100 (Di, 01. Dez 2009) by jonasha for revision 4010

Method Summary
static String getClassPath(Class<?> mainClass)
           
static String[] getURLs(Class<?> mainClass)
           
static boolean isURLLoaded(Class<?> mainClass)
          Checks whether a class is loaded via an URLClassLoader, in which case a call to getClassPath will work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isURLLoaded

public static boolean isURLLoaded(Class<?> mainClass)
Checks whether a class is loaded via an URLClassLoader, in which case a call to getClassPath will work.

Parameters:
mainClass - The class to check.
Returns:
Whether this class was loaded via an URLClassLoader.

getClassPath

public static String getClassPath(Class<?> mainClass)
                           throws RuntimeException
Parameters:
mainClass - A class from which to obtain the classloader and its classpath.
Returns:
A comma-separated list of the modules on the current maven classpath.
Throws:
RuntimeException - - if the class does not come from an URLClassLoader

getURLs

public static String[] getURLs(Class<?> mainClass)
                        throws RuntimeException
Parameters:
mainClass - A class from which to obtain the classloader and its classpath.
Returns:
A String[] of the modules on the current maven classpath.
Throws:
RuntimeException - - if the class does not come from an URLClassLoader


Copyright © 2005-2011 ELCA. All Rights Reserved.