Java Utililty Methods ClassLoader

List of utility methods to do ClassLoader

Description

The list of methods to do ClassLoader are organized into topic(s).

Method

voidadd(File file)
add
try {
    add(file.toURI().toURL());
} catch (Exception ex) {
voidaddDirectory(File directory)
add Directory
if (directory.isDirectory()) {
    File[] jars = directory.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isFile() && pathname.getName().endsWith(".jar");
    });
    for (File jar : jars) {
...
voidAddFile(File f)
Add File
AddURL(f.toURL());
booleanaddFile(File file)
Add a file to the classpath.
try {
    return addURL(file.toURI().toURL());
} catch (Exception ex) {
    return false;
voidaddFile(String s)
Add file to CLASSPATH
File f = new File(s);
addFile(f);
FilecreateDir(String pathName)
create Dir
File dir = new File(getClasspathRootDir() + pathName);
if (!dir.exists())
    dir.mkdir();
return dir;
ClassLoadercreateDirectoryLoader(String directory)
This method returns a new ClassLoader object that can be used to load classes from files contained by the specified directory.
Collection<URL> urls = new ArrayList<URL>();
File dir = new File(directory);
File[] files = dir.listFiles();
for (File f : files) {
    System.out.println(f.getCanonicalPath());
    urls.add(f.toURI().toURL());
return URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]));
...
voidCreateLogbackXML(OutputStream out)
Create Logback XML
Enumeration<URL> logback_xml_urls;
logback_xml_urls = Thread.currentThread().getContextClassLoader().getResources("logback.xml");
while (logback_xml_urls.hasMoreElements()) {
    URL logback_xml_url = logback_xml_urls.nextElement();
    if (logback_xml_url.getProtocol().equals("file")) {
        FileInputStream is = new FileInputStream(logback_xml_url.getPath());
        while (is.available() > 0) {
            out.write(is.read());
...
FilefindFile(String filename)
searches the classpath for a filename and returns a File object
URL url = ClassLoader.getSystemResource(filename);
return new File(url.getFile());
booleanhasImageFile(String name)
Checks whether the image is available.
return (getImageFilename(name) != null);