java

mathpunk 2018-04-07T19:11:54.000007Z

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?

seancorfield 2018-04-07T19:14:40.000089Z

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

seancorfield 2018-04-07T19:24:06.000043Z

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

seancorfield 2018-04-07T19:25:19.000025Z

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

mathpunk 2018-04-07T19:27:35.000048Z

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

mathpunk 2018-04-07T19:27:52.000055Z

hey wow that's unreadable sorry

mathpunk 2018-04-07T19:29:08.000049Z

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.

seancorfield 2018-04-07T19:31:19.000014Z

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

seancorfield 2018-04-07T19:33:16.000016Z

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

seancorfield 2018-04-07T19:33:41.000094Z

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

seancorfield 2018-04-07T19:34:04.000037Z

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

seancorfield 2018-04-07T19:35:18.000058Z

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

mathpunk 2018-04-07T19:35:22.000110Z

yes

seancorfield 2018-04-07T19:35:42.000021Z

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

seancorfield 2018-04-07T19:37:28.000049Z

You might want to check that the JAR you built has all the expected dependencies in it -- size-wise I see

(! 1093)-&gt; 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

mathpunk 2018-04-07T19:38:06.000021Z

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

seancorfield 2018-04-07T19:38:39.000061Z

The JAR downloaded from the GitHub releases page has a lot of stuff in it

(! 1092)-&gt; 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?

mathpunk 2018-04-07T19:44:47.000024Z

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

mathpunk 2018-04-07T19:45:13.000142Z

https://github.com/appliedtopology/javaplex/releases/

seancorfield 2018-04-07T19:48:54.000088Z

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

seancorfield 2018-04-07T19:50:03.000001Z

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

seancorfield 2018-04-07T19:52:41.000007Z

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.

seancorfield 2018-04-07T19:53:20.000085Z

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

seancorfield 2018-04-07T19:53:53.000108Z

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

mathpunk 2018-04-07T19:55:37.000031Z

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

mathpunk 2018-04-07T19:57:48.000032Z

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

seancorfield 2018-04-07T19:58:10.000107Z

You got it working?

mathpunk 2018-04-07T19:59:42.000049Z

yep! looks like I can instantiate an empty complex

seancorfield 2018-04-07T19:59:48.000017Z

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

1
mathpunk 2018-04-07T19:59:49.000081Z

off to the races

seancorfield 2018-04-07T19:59:59.000082Z

Yay! My work here is done! 🙂

seancorfield 2018-04-07T20:00:14.000012Z

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

mathpunk 2018-04-07T22:38:59.000094Z

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

mathpunk 2018-04-07T22:39:24.000002Z

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

mathpunk 2018-04-07T22:41:20.000038Z

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

seancorfield 2018-04-07T22:45:10.000072Z

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

mathpunk 2018-04-07T22:45:45.000091Z

ahhhh

mathpunk 2018-04-07T22:45:56.000070Z

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

seancorfield 2018-04-07T22:46:33.000047Z

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

seancorfield 2018-04-07T22:48:39.000071Z

I don't know what the point argument should be -- the class "helpfully" indicates it's any type T that extends java.lang.Compartor&lt;T&gt; which is a pretty broad range of things 🙂

mathpunk 2018-04-07T22:51:54.000065Z

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

mathpunk 2018-04-07T22:53:40.000038Z

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

seancorfield 2018-04-07T23:05:30.000072Z

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 🙂