The list of methods to do ClassLoader are organized into topic(s).
void
add(File file) add
try {
add(file.toURI().toURL());
} catch (Exception ex) {
void
addDirectory(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) {
...
boolean
addFile(File file) Add a file to the classpath.
try {
return addURL(file.toURI().toURL());
} catch (Exception ex) {
return false;
File
createDir(String pathName) create Dir
File dir = new File(getClasspathRootDir() + pathName);
if (!dir.exists())
dir.mkdir();
return dir;
ClassLoader
createDirectoryLoader(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()]));
...
void
CreateLogbackXML(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());
...
File
findFile(String filename) searches the classpath for a filename and returns a File object
URL url = ClassLoader.getSystemResource(filename);
return new File(url.getFile());