From f3bb7f3d238b916b861fedaaad50f6d3f756531d Mon Sep 17 00:00:00 2001 From: "dziltener@lyrion.ch" Date: Fri, 17 Nov 2017 09:10:27 +0000 Subject: [PATCH] Added forgotten file --- src/clojurefx/FXClassLoader.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/clojurefx/FXClassLoader.java diff --git a/src/clojurefx/FXClassLoader.java b/src/clojurefx/FXClassLoader.java new file mode 100644 index 0000000..8ec49a8 --- /dev/null +++ b/src/clojurefx/FXClassLoader.java @@ -0,0 +1,28 @@ +package clojurefx; + +public class FXClassLoader { + + public static Class loadClass(String className, byte[] b) { + //override classDefine (as it is protected) and define the class. + Class clazz = null; + try { + ClassLoader loader = ClassLoader.getSystemClassLoader(); + Class cls = Class.forName("java.lang.ClassLoader"); + java.lang.reflect.Method method = + cls.getDeclaredMethod("defineClass", new Class[] { String.class, byte[].class, int.class, int.class }); + + // protected method invocaton + method.setAccessible(true); + try { + Object[] args = new Object[] { className, b, new Integer(0), new Integer(b.length)}; + clazz = (Class) method.invoke(loader, args); + } finally { + method.setAccessible(false); + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + return clazz; + } +}