Problems with importing package from Github - clojure

before I start, you probably need to know three things:
I don't have Java background
I'm a Clojure newbie - started to learn it
question is related to my "training" package kennyfy
TL;DR version I'm not able to import/use my training package in a project
Longer version
I set myself a goal - write simple API which converts text to kennyspeak. Before that I've created a package (using default lein template).
I tried to import this package to my API.
Part of project.clj looks like this:
:repositories [["jitpack" "https://jitpack.io"]]
:dependencies [[com.github.radmen/clojure-kennyfy "0.1.2"]]
lein deps fetches the package without any problems.
When I try to use it, Clojure fails with following message:
kennyfy-api.core=> (radmen.kennyfy/kenny-speak "foo")
ClassNotFoundException radmen.kennyfy java.net.URLClassLoader.findClass (URLClassLoader.java:382)
I understand the error, yet I've no idea why this class is not imported.
I am quite sure, that this may be related to the metadata stored in the package, which results in failed imports.
What am I doing wrong?
Thank you
$ java -version
openjdk version "1.8.0_192"
OpenJDK Runtime Environment (build 1.8.0_192-b26)
OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)
$ lein version
Leiningen 2.8.3 on Java 1.8.0_192 OpenJDK 64-Bit Server VM
Clojure 1.9.0

A clojure namespaces is loaded the first time it is required.
foo.core=> (radmen.kennyfy/kenny-speak "foo")
Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:382).
radmen.kennyfy
foo.core=> (require '[radmen.kennyfy :as kennyfy])
nil
foo.core=> (kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=> (radmen.kennyfy/kenny-speak "foo")
"mpfppfppf"
foo.core=>

Related

cljs/core.cljs [line 988, col 14] No reader function for tag Inf

I'm trying to launch the latest stable [org.clojure/clojurescript "1.9.946"], using boot-cljs and getting this error: cljs/core.cljs [line 988, col 14] No reader function for tag Inf.
I've learned that 1.9.946 introduced new ##Inf syntax: https://cljs.github.io/api/syntax/Inf. but not sure why I'm getting this error. I've also tried to do this: [adzerk/boot-cljs "2.1.4" :exclusions [org.clojure/clojurescript]] but it changed nothing.
Edit: just tried to build cljs version from repo and hooked up npm deps with lein-npm, server rendering of react worked as expected. May be something to do with boot-cljs deps or some other my components.
Support for ##Inf was added in tools.reader 1.1.0, which ClojureScript 1.9.946 depends upon.
If you see this error, it is because you have tools.reader 1.0.6 or earlier on your classpath.
Note that, while ClojureScript 1.9.946 specifies [org.clojure/tools.reader "1.1.0"] as a dependency, explicitly specifying an older version in your project configuration would cause the issue.
Also note that this is independent of the Clojure version being used. If desired, you can run the ClojureScript 1.9.946 compiler using Clojure 1.8.0 and successfully compile ClojureScript code that makes use of ##Inf; Clojure 1.9.0 is not required.

imagez load-image-resource complains "no implementation of method: :as-image"

On my Mac using [net.mikera/imagez "0.12.0"] when I run the example code to load an image I get an exception:
user> (def ant (load-image-resource "mikera/image/samples/Ant.png"))
CompilerException java.lang.IllegalArgumentException: No implementation of method: :as-image of protocol: #'mikera.image.protocols/ImageResource found for class: nil, compiling:(form-init214709365644880775.clj:59:16)
I'm running this code from within a Leiningen/Luminus project.
Perhaps I'm missing some dependencies for working with images?
My java version:
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
To fix create a directory called resources. It will be a sibling of a directory you probably already have src. Put your file "Ant.png" in this directory. Then you could simply have this:
(def ant (load-image-resource "Ant.png"))
The library you are using is using the clojure function resource to load the image. Because the file Ant.png is not on the resource path, the call to resource is returning nil, which is why you're seeing this message. So, you need to add the path to your images as follows, in your project.clj:
:resource-paths ["/full/path/to/mikera/image/samples"]
Then in your code, reference the file as:
(def ant (load-image-resource "Ant.png"))

Using a mirror of Clojars from Leiningen

The following Wiki page describes a straightforward way of setting up Leiningen to use a mirror of Clojars.org: https://github.com/clojars/clojars-web/wiki/Mirrors
Based on this, I have put the following as my ~/.lein/profiles.clj:
{:user {:mirrors
{#"clojars" {:name "clojars mirror"
:url "https://clojars-mirror.tcrawley.org/repo/"}}}}
However, even with this profiles.clj, I can still see in e.g. Wireshark that lein is trying to connect to clojars.org instead of clojars-mirror.tcrawley.org. What setting am I missing?
My Leiningen version is
Leiningen 2.5.3 on Java 1.7.0_91 OpenJDK 64-Bit Server VM
I couldn't get a mirror working by modifying profile.clj either.
However I was able to get it working for a specific project.clj by adding this within defproject
:mirrors {#"clojars" {:name "Clojar Mirror"
:url "https://clojars-mirror.tcrawley.org/repo/"
:repo-manager true}}
Notes:
This came from the official Leiningen sample project.clj:
https://github.com/technomancy/leiningen/blob/master/sample.project.clj
I tried following the below for global setting in profile.clj (the syntax is somewhat different from yours) but had no luck:
https://github.com/technomancy/leiningen/issues/271#issuecomment-21108691
https://stackoverflow.com/a/17697119/617320

Lein console (like sbt)

Is there some built-in functionality or plugin to lein to get a lein console, so for example one could test without waiting every time for JVM to start up.
$ lein console
>>> test
...
>>> test
...
>>> jar
Note: I'd like to trigger test runs myself, not e.g. by watching source files. That's why I'd like to have a lein console.
Clarification: I'm not looking for lein repl. I'd like to have a console where I could run lein task commands.
Older versions of leiningen used to include lein interactive, which behaved much like the feature you are asking for: it opened a shell into which you could type test and have it run lein test from the already-running lein jvm, and so on. This feature was removed in the transition to lein 2.0, I think, and although I don't know why I suspect there was a good reason. Maybe try asking in #leiningen on freenode?
You might want to have a look at grenchman. While it's not a Leiningen console it at least enables reusing of an existing REPL session. From what I gather, usage is as follows:
Move somewhere that is not inside a project and call:
$ lein repl :headless
Within your project directory, use:
$ grench lein <task> <options>
Tasks will be run inside the already spun up Leiningen JVM and the startup overhead should disappear.
Building grenchman seems to be tedious, though, and it is recommended to use one of the precompiled binaries (BUT they are currently not available).
And finally, that page also states:
Grenchman is still very new and may not be fully reliable.
So, good luck, I guess?
One option is to run a repl from leiningen's own jar file.
$ java -cp ~/.lein/self-installs/leiningen-2.5.0-standalone.jar clojure.main
Clojure 1.6.0
user=> (require '[leiningen.core.project :as project] '[leiningen.test :as test])
nil
user=> (def prj (project/read))
#'user/prj
user=> (test/test prj)
lein test org.noisesmith.orsos.load-test
Ran 3 tests containing 3 assertions.
0 failures, 0 errors.
nil
user=> (require '[leiningen.jar :as jar])
nil
user=> (jar/jar prj 'org.noisesmith.orsos)
Compiling org.noisesmith.orsos
Created /media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar
{[:extension "jar"] "/media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar"}
user=>
As a baseline, this can run lein tasks without having to restart lein every time. If you also use rlwrap or use nrepl it becomes a bit more usable. As far as I know there is no user friendly tooling around this (though there easily could be).
If you wish to use tasks from lein plugins those can be added to the -cp arg.

Clojure: how to explicitly choose JVM in the environment with Leiningen/Lighttable

In my Windows 7 (64 bits) environment, I have quite a few JVM available:
C:\Program Files (x86)\Java\j2re1.4.2_12\bin\client\jvm.dll
C:\Program Files (x86)\Java\jre6\bin\client\jvm.dll
D:\programs\Java\jdk1.7.0_45\jre\bin\server\jvm.dll
D:\programs\Java\jre7\bin\server\jvm.dll
Currently, with Lighttable/Leiningen (I don't know which makes the choice, and how), it uses
C:\Program Files (x86)\Java\j2re1.4.2_12\bin\client\jvm.dll
But I really would like to try
D:\programs\Java\jdk1.7.0_45\jre\bin\server\jvm.dll
It's even more puzzling that when I type
java -version
I got the following:
D:\yushen>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
It seems that's what I want to have inside Lighttable/Leinengen.
Could you show me how to make the explicit choice/configuration?
I tried Google, but couldn't find some leads.
Thanks a lot!
I found a Leiningen profile in
$HOME/.lein/profiles.clj
For me on Windows, $HOME was D:\Users\carl . More generally, it's the directory Windows will (usually) dump you in if you start the shell using CMD .
This contained:
{:user
{
:java-cmd "F:\\JDK8\\bin\\java.exe"
:plugins [
]
}
}
...which I was able to change to good effect.
Put the JDK's bin directory in your path first. It's the surest way.
More detail. Windows, you can use the where command to see what version of an executable. It's either where java or where java.exe You can also look at your path from the command prompt by typing path. If you're launching something from the command line, and it's not undertaking strange measures to find the JVM, it should come up with the first one in your path, which should agree with the results of running the where command.
If the where command is coming up with something you don't expect, either add the right directory to your path before the entry that's coming up or rearrange your path so it's coming up first.
To test this in leiningen, start a repl, and evaluate this.
(println (System/getProperty "java.version"))
e.g.
Yoyo-2:Desktop bill$ lein repl
(System/getPnREPL server started on port 61475 on host 127.0.0.1 - nrepl://127.0.0.1:61475
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_20-b26
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e
ruser=> (System/getProperty "java.version")
"1.8.0_20"
In my experience, Leiningen has always used the version of java it finds in the path. No experience with light table though.
For Leiningen, you can edit lein.bat to point exactly to your desired Java SDK version. I don't know if the same could apply to LightTable.
Or you can set a global JAVA_HOME. That is really Googleable (or DuckDuckGo-able).
Finally, I found this link: http://leiningen-win-installer.djpowell.net/
After running the installer, it has the function to re-configure leiningen, using it, I was able to configure my old leiningen to use my desired JDK: D:\programs\Java\jdk1.7.0_45\bin\java.exe, then the JVM instance in leiningen/lighttable is the desired one now.
The moral of the story: leiningen needs to be reconfigured with newly installed JDK with the configuration functionality of leiningen-win-installer.
It might be possible to configure leiningen manually, but I hadn't found a way to do yet.
I tried to manually configure through my project.clj with java-command option, it didn't work.