Fixed: library can't be used from Boot projects
This commit is contained in:
parent
6ccbb59858
commit
50a6258807
2 changed files with 12 additions and 32 deletions
|
@ -1,28 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -2,8 +2,7 @@
|
|||
;; (:gen-class :name Controllergen
|
||||
;; :implements [org.objectweb.asm.Opcodes])
|
||||
;; (:import (net.openhft.compiler CachedCompiler CompilerUtils))
|
||||
(:import (org.objectweb.asm ClassWriter Opcodes)
|
||||
clojurefx.FXClassLoader)
|
||||
(:import (org.objectweb.asm ClassWriter Opcodes))
|
||||
(:use swiss.arrows)
|
||||
(:require [clojure.xml :as xml]
|
||||
[clojure.zip :as zip]
|
||||
|
@ -175,6 +174,15 @@
|
|||
|
||||
;; ;; Plumber
|
||||
|
||||
(defn define-class [name bytes]
|
||||
(let [cl (.getClassLoader clojure.lang.RT)
|
||||
method (.getDeclaredMethod java.lang.ClassLoader "defineClass"
|
||||
(into-array [String (Class/forName "[B") (Integer/TYPE) (Integer/TYPE)]))]
|
||||
(try
|
||||
(.setAccessible method true)
|
||||
(.invoke method cl (into-array Object [name bytes (int 0) (int (count bytes))]))
|
||||
(finally (.setAccessible method false)))))
|
||||
|
||||
(defn gen-fx-controller-class [fxmlpath clj-fn]
|
||||
(let [clj-fn ^String (if (symbol? clj-fn)
|
||||
(str (namespace clj-fn) "/" (name clj-fn))
|
||||
|
@ -186,5 +194,5 @@
|
|||
(try
|
||||
(Class/forName (str pkg "." classname))
|
||||
(catch Exception e
|
||||
(FXClassLoader/loadClass (str pkg "." classname)
|
||||
(define-class (str pkg "." classname)
|
||||
(gen-fx-controller fxmlzip fxmlpath cljvec [pkg classname]))))))
|
||||
|
|
Loading…
Reference in a new issue