package entitygen;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

public class FileClassLoader extends ClassLoader {

	public FileClassLoader() {
		// Empty
	}

	public Class<?> nameToClass(String className, String fileName) {
		try (InputStream is = new FileInputStream(fileName);) {
			int n = is.available();
			byte[] bytes = new byte[n];
			int ret = is.read(bytes, 0, n);
			if (ret != n) {
				throw new IOException("Expected " + n + " bytes but read " + ret);
			}
			ByteBuffer data = ByteBuffer.wrap(bytes);
			return 	defineClass(className, data, null);
		} catch (IOException e) {
			throw new RuntimeException("Couldnt open " + className + "(" + e + ")", e);
		}
		
	}
}

@@ -13,16 +13,37 @@
 tygen;%0A%0A
+import java.io.File;%0A
 import j
@@ -155,98 +155,527 @@
 r;%0A%0A
-public class FileClassLoader extends ClassLoader %7B%0A%0A%09public FileClassLoader() %7B%0A%09%09// Empty
+/**%0A * Plain File-based class loader%0A * @author Ian Darwin%0A */%0Apublic class FileClassLoader extends ClassLoader %7B%0A%0A%09private final String dir;%0A%0A%09public FileClassLoader(String dir) %7B%0A%09%09this.dir = dir;%0A%09%7D%0A%09%0A%09@Override%0A%09public Class%3C?%3E loadClass(String className) throws ClassNotFoundException %7B%0A%09%09String fileName = dir + %22/%22 + className.replaceAll(%22%5C%5C.%22, %22/%22) + %22.class%22;%0A%09%09if (new File(fileName).exists()) %7B%0A%09%09%09return nameToClass(className, fileName);%0A%09%09%7D else %7B%0A%09%09%09return getSystemClassLoader().loadClass(className);%0A%09%09%7D
 %0A%09%7D%0A
@@ -794,17 +794,16 @@
 ileName)
-;
 ) %7B%0A%09%09%09i

Make it grow up to be a real ClassLoader