Skip to content

Instantly share code, notes, and snippets.

@nfisher
Created September 27, 2017 00:04
Show Gist options
  • Save nfisher/94f31de6728e149ea45ae2b4e0328fdb to your computer and use it in GitHub Desktop.
Save nfisher/94f31de6728e149ea45ae2b4e0328fdb to your computer and use it in GitHub Desktop.
Call clojure FN from JAR file
public class Call {
public void printPlus() {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final Class c = Class.forName("clojure.lang.RT", true, classLoader);
final Method method = c.getDeclaredMethod("var", String.class, String.class);
Object var = method.invoke(null, "clojure.core", "+");
Class<?> varClass = var.getClass();
final Method plus = varClass.getDeclaredMethod("invoke", Object.class, Object.class, Object.class);
System.out.println(plus.invoke(var, 1, 2, 3));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment