All pastes #747252 Raw Edit

Something

public java v1 · immutable
·published 2007-10-23 21:20 UTC
rendered paste body
package main;import java.io.*;import java.net.*;public class ModuleLoader extends ClassLoader {	String path;	public static Class load(String filename) {		return (new ModuleLoader()).loadIt(new File(filename));	}	Class loadIt(File f) {		System.out.println(f.getAbsolutePath());		String filename = f.getPath();		path = filename.substring(0, filename.lastIndexOf(f.separator) + 1);		if (!filename.endsWith(".class")) {			filename += ".class";		}		try {			InputStream is = new FileInputStream(filename);			byte buf[] = new byte[is.available()];			is.read(buf, 0, is.available());			is.close();			// Define and resolve the class.			Class c = defineClass(null, buf, 0, buf.length);			if (c != null) {				super.resolveClass(c);			}			return c;		} catch (Exception e) {		}		return null;	}	protected Class loadClass(String name, boolean resolve)	throws ClassNotFoundException {		System.out.println(name);		path="modules\\";		try {			if(name.indexOf("modules.")<0)			return findSystemClass(name);		} catch (ClassNotFoundException e) {		}		if (name.indexOf(".") >= 0) {			name = name.substring(name.lastIndexOf(".") + 1);		}						return loadIt(new File(path + name));	}	public URL getResource(String name) {		try {			File file = new File(path);			String absPath = file.getAbsolutePath().replace(file.separatorChar, '/');			return new URL("file:///" + absPath + name);		} catch (MalformedURLException e) {			e.printStackTrace();		}		return null;	}	public InputStream getResourceAsStream(String name) {		try {			return new FileInputStream(path + name);		} catch (FileNotFoundException e) {			e.printStackTrace();		}		return null;	}}