Problem
I cannot load and call methods in a compiled class c in a leiningen project. My basic approach is to load the Java class JavaWrapper.java, which uses the JNI to call some of its own methods in its own code, wrapper.o, and then calls methods through this java shell class.
I assume that there are problems with the Loader class loading a java class that loads its own code from the clojure project, but on the condition that I cannot directly get the clojure code to find wrapper.o in the library path, I'm not sure how to deal with by this.
lein project file
(defproject lein-native-test "0.1.0-SNAPSHOT" ... :java-source-paths ["java-path"] :jvm-opts ["-Djava.library.path=.:./native:/absolute/path/to/native"] ;;not sure what format it wants )
clojure file with the main method
I tried to modify it slightly using four approaches, all of which are included in the code below along with the corresponding error in the comments.
(ns lein-native-test.core (:import (com.test JavaWrapper))) (def -main [] ;;four things I've tried and their errors (clojure.lang.RT.load "/abs/path/to/wrapper.o") ;;could not find file /abs/path/wrapper.o_init.class or wrapper.o.clj (clojure.lang.RT.loadLibrary "wrapper.o") ;;UnsatisfiedLinkError no wrapper.o in java library path (JavaWrapper/load "/abs/path/to/wrapper.o") ;;UnsatisfiedLinkError com.test.JavaWrapper.setup() (assembly-load "/abs/path/to/wrapper.o") ;;unable to resolvesymbol: assembly-load )
Java code with native methods that uses JNI, JavaWrapper.java
public class JavaWrapper{ public native void setup(); public static void load(String lib){ System.load(lib);} }
Before trying to get this to work with clojure and lein, I successfully downloaded and used my own methods in wrapper.o through JavaWrapper and JNI.
Perhaps related:
I also cannot load wrapper.o in JavaWrapper.java via
System.loadLibrary("wrapper.o");
I need to use
System.load("/absolute/path/to/wrapper.o");
Tool versions
clojure version: 1.5.1
lane version: 2.3.4
jdk: 1.7
os: debian7
A better understanding of ClassLoaders or a particularly working simple example would be very helpful, thanks.