I'm trying to use a Java library. I created a jar from the source code, put that in my ~/.m2 path, added a matching line to :dependencies in my project.clj, and lein deps
doesn't complain. But, I'm not clear how to access this in a namespace to start tinkering with it. An import
statement?
@mathpunk Yes, (import (the.package.name MyClass))
for example (in the REPL -- it would be (:import ...)
inside your (ns ...)
form).
@mathpunk You'd be safer you use lein-localrepo
to modify the .m2
cache tree than update it yourself (for pom
files etc).
What does your actual import
look like and what is the error you get?
`(ns simplexity.repl (:import [edu.stanford.math.plex4.streams.impl ExplicitSimplexStream]))`, when evaluated, yields `1. Unhandled java.lang.ClassNotFoundException edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream URLClassLoader.java: 381 java.net.URLClassLoader/findClass DynamicClassLoader.java: 69 clojure.lang.DynamicClassLoader/findClass`
hey wow that's unreadable sorry
I think I created a jar file for the first time for this project, and I'm realizing I thought 'maven' was like 'clojars' but it's something different. There's a lot of places I could be losing the plot.
When I install the JAR locally with lein-localrepo
I have this
(! 1083)-> tree ~/.m2/repository/appliedtopology/
| | | | | |____
| | | | | | |____javaplex
| | | | | | | |____4.3.1
| | | | | | | | |_____remote.repositories
| | | | | | | | |____javaplex-4.3.1.jar
| | | | | | | | |____javaplex-4.3.1.pom
| | | | | | | |____maven-metadata-local.xml
I used Boot but the same principle should apply:
(! 1089)-> boot -d appliedtopology/javaplex:4.3.1 repl
nREPL server started on port 57128 on host 127.0.0.1 - <nrepl://127.0.0.1:57128>
...
boot.user=> (import (edu.stanford.math.plex4.streams.impl ExplicitSimplexStream))
edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream
boot.user=>
That's after installing it locally with
boot -d leiningen -d lein-localrepo call -e "(require '[leiningen.localrepo :as lr])" -e '(lr/localrepo nil "install" "javaplex.jar" "appliedtopology/javaplex" "4.3.1")'
With Leiningen, that would be shorter, but I don't use Leiningen any more 🙂
Is your :dependencies
entry [appliedtopology/javaplex "4.3.1"]
?
yes
(BTW, I didn't build it from source, I downloaded the JAR from GitHub)
You might want to check that the JAR you built has all the expected dependencies in it -- size-wise I see
(! 1093)-> ls -l ~/.m2/repository/appliedtopology/javaplex/4.3.1/javaplex-4.3.1.jar
-rw-r--r-- 1 sean staff 4326930 Jun 26 2017 /Users/sean/.m2/repository/appliedtopology/javaplex/4.3.1/javaplex-4.3.1.jar
i'll download the jar, i only built it b/c i missed that download link
The JAR downloaded from the GitHub releases page has a lot of stuff in it
(! 1092)-> jar tf ~/.m2/repository/appliedtopology/javaplex/4.3.1/javaplex-4.3.1.jar |wc
3533 3533 171691
So maybe the JAR you built was only a partial version of the full library?From where did you download this jar? I am looking at the releases page, and seeing only source, docs, and demos
This link https://github.com/appliedtopology/javaplex/files/1103657/javaplex-processing-lib-4.3.1.zip
Then unzip that and the javaplex.jar file is inside.
(hidden between the processing demo and the matlab examples on the releases page)
If you have lein-localrepo
in your Leiningen :plugins
list, you should then be able to install it
lein localrepo install path/to/javaplex.jar appliedtopology/javaplex 4.3.1
and then use it, like I did above.Here's the link to lein-localrepo
if you need it https://github.com/kumarshantanu/lein-localrepo
(or, if you already have Boot installed, just copy and paste the long line I used above! 🙂 )
"learn to boot" is on a list somewhere....
@seancorfield :thumbsup::skin-tone-2:
You got it working?
yep! looks like I can instantiate an empty complex
(and, yeah, Boot makes so much of this stuff just so much easier than Leiningen -- firing up a REPL anywhere with whatever dependencies you want, from the command line, with no need for a project file... being able to extend it by just writing regular Clojure functions... the core tooling itself is so much more powerful than Leiningen... and, it only starts one JVM, not two, so it's faster to get things up and running)
off to the races
Yay! My work here is done! 🙂
(now I can go shower and find lunch! 🙂 )
What's surprising me in the above is, BarcodeCollection supposedly inherits getBettiNumbersMap from edu.stanford.math.plex4.homology.barcodes.AnnotatedBarcodeCollection
I figured, maybe I needed to import it, but that doesn't seem to have changed anything
I also tried a form like [edu.stanford.math.plex4.homology.barcodes BarcodeCollection AnnotatedBarcodeCollection]
.getBettiNumbersMap
expects a point
argument: (.getBettiNumbersMap barcodes my-point)
ahhhh
"Not Found" meaning, not found with that arity / type signature
Right, when it used reflection, it couldn't find a match with no arugments.
I don't know what the point
argument should be -- the class "helpfully" indicates it's any type T
that extends java.lang.Compartor<T>
which is a pretty broad range of things 🙂
yeah it's not well named --- I hit it with a stick and discovered that a Double will work
I think they meant something called the 'filtration index' --- the test object should have the same Betti numbers for any positive number and that seems to be true here
The math looks a bit above my pay grade (I did some pretty advanced math at university in England but don't recognize much of what's in the docs for this library), but I'm happy to help with the Java and/or Clojure side of things 🙂