Fork me on GitHub
#java
<
2018-04-07
>
mathpunk19:04:54

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?

seancorfield19:04:40

@mathpunk Yes, (import (the.package.name MyClass)) for example (in the REPL -- it would be (:import ...) inside your (ns ...) form).

seancorfield19:04:06

@mathpunk You'd be safer you use lein-localrepo to modify the .m2 cache tree than update it yourself (for pom files etc).

seancorfield19:04:19

What does your actual import look like and what is the error you get?

mathpunk19:04:35

`(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`

mathpunk19:04:52

hey wow that's unreadable sorry

mathpunk19:04:08

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.

seancorfield19:04:19

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

seancorfield19:04:16

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 - 
...
boot.user=> (import (edu.stanford.math.plex4.streams.impl ExplicitSimplexStream))
edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream
boot.user=> 

seancorfield19:04:41

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")'

seancorfield04:04:27

I can't even read my own blog post... right at the bottom it points to a Boot version of "localrepo" so you could simply do

boot -d seancorfield/boot-localrepo install-artifact -f javaplex.jar -P appliedtopology/javaplex -v 4.3.1
I'd forgotten I'd even written that!

seancorfield19:04:04

With Leiningen, that would be shorter, but I don't use Leiningen any more 🙂

seancorfield19:04:18

Is your :dependencies entry [appliedtopology/javaplex "4.3.1"]?

seancorfield19:04:42

(BTW, I didn't build it from source, I downloaded the JAR from GitHub)

seancorfield19:04:28

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

mathpunk19:04:06

i'll download the jar, i only built it b/c i missed that download link

seancorfield19:04:39

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?

mathpunk19:04:47

From where did you download this jar? I am looking at the releases page, and seeing only source, docs, and demos

seancorfield19:04:54

Then unzip that and the javaplex.jar file is inside.

seancorfield19:04:03

(hidden between the processing demo and the matlab examples on the releases page)

seancorfield19:04:41

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.

seancorfield19:04:20

Here's the link to lein-localrepo if you need it https://github.com/kumarshantanu/lein-localrepo

seancorfield19:04:53

(or, if you already have Boot installed, just copy and paste the long line I used above! 🙂 )

mathpunk19:04:37

"learn to boot" is on a list somewhere....

mathpunk19:04:48

@seancorfield :thumbsup::skin-tone-2:

seancorfield19:04:10

You got it working?

mathpunk19:04:42

yep! looks like I can instantiate an empty complex

seancorfield19:04:48

(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)

4
mathpunk19:04:49

off to the races

seancorfield19:04:59

Yay! My work here is done! 🙂

seancorfield20:04:14

(now I can go shower and find lunch! 🙂 )

mathpunk22:04:59

What's surprising me in the above is, BarcodeCollection supposedly inherits getBettiNumbersMap from edu.stanford.math.plex4.homology.barcodes.AnnotatedBarcodeCollection

mathpunk22:04:24

I figured, maybe I needed to import it, but that doesn't seem to have changed anything

mathpunk22:04:20

I also tried a form like [edu.stanford.math.plex4.homology.barcodes BarcodeCollection AnnotatedBarcodeCollection]

seancorfield22:04:10

.getBettiNumbersMap expects a point argument: (.getBettiNumbersMap barcodes my-point)

mathpunk22:04:56

"Not Found" meaning, not found with that arity / type signature

seancorfield22:04:33

Right, when it used reflection, it couldn't find a match with no arugments.

seancorfield22:04:39

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 🙂

mathpunk22:04:54

yeah it's not well named --- I hit it with a stick and discovered that a Double will work

mathpunk22:04:40

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

seancorfield23:04:30

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 🙂

seancorfield04:04:27

I can't even read my own blog post... right at the bottom it points to a Boot version of "localrepo" so you could simply do

boot -d seancorfield/boot-localrepo install-artifact -f javaplex.jar -P appliedtopology/javaplex -v 4.3.1
I'd forgotten I'd even written that!