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"))
Related
I am watching a course/tutorial from Eric Normand on
front-end. The
course is a paid private service.
However, he is using a public repo on GitHub, this
one.
After cloning and executing lein fig-dev, the project seems to have
been succesfully built:
2022-08-25 13:46:47.988:INFO::main: Logging initialized #3006ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Validating figwheel-main.edn
[Figwheel] figwheel-main.edn is valid \(ツ)/
[Figwheel] Compiling build dev to "resources/public/js/compiled/app.js"
[Figwheel] Successfully compiled build dev to "resources/public/js/compiled/app.js" in 1.33 seconds.
[Figwheel] Watching paths: ("src") to compile build - dev
[Figwheel:SEVERE] /private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp: dlopen(/private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp, 0x0001): tried: '/private/var/folders/fh/7d_1drwd2ps3zw03j9ftkqs80000gn/T/jna1153974339277798676.tmp' (fat file, but missing compatible architecture (have (unknown,i386,x86_64), need (arm64e)))
[Figwheel] Starting Server at http://localhost:3449
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
(figwheel.main/stop-builds id ...) ;; stops Figwheel autobuilder for ids
(figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
(figwheel.main/reset) ;; stops, cleans, reloads config, and starts autobuilder
(figwheel.main/build-once id ...) ;; builds source one time
(figwheel.main/clean id ...) ;; deletes compiled cljs target files
(figwheel.main/status) ;; displays current state of system
Figwheel REPL Controls:
(figwheel.repl/conns) ;; displays the current connections
(figwheel.repl/focus session-name) ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
Docs: (doc function-name-here)
Exit: :cljs/quit
Results: Stored in vars *1, *2, *3, *e holds last exception object
Opening URL http://localhost:3449
ClojureScript 1.10.764
cljs.user=> (js/alert "hello")
nil
This is all my log (question was asked as comment below).
The browser starts (I am using Brave) and the application seems to be
succesfully loaded on http://localhost:3449//.
I have a REPL working and I can even do alerts like that happen as
events on the browser at localhost:
cljs.user=> (js/alert "hello")
nil
Ok. The only problem is when I edit the sorce code as he does on the
videos. In his case, the changes make effect on the browser. On my
case, they do not. Nothing happens.
I can only see changes if I rebuilt everything from scratch.
In other projects, I managed to see the changes happening live, but I
was using shadow-cljs there.
How do I fix this?
Obs.: I am using Macbook M1, macOS Monterey 12.5.1
The Hawk filewatcher used in the version of figwheel-main you have does not support the M1 Mac -- that's what the JNA-related SEVERE error is about in the logs.
The current version of figwheel-main is 0.2.18 so you can try that instead of 0.2.12 in project.clj. According to the changelog, 0.2.14 switched from Hawk to Beholder so it may fix the M1 compatibility issue.
Thanks to #SearCorfield, I managed to solve the problem.
Also, Eric Normand (the creator of the course and author of the
repository) has
just updated the project.clj file to have
[com.bhauman/figwheel-main "0.2.18"]. It now works smoothly!
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=>
I have set up Datomic database up and running within a Clojure project. It is working fine when running my unit tests against it BUT:
Now I want to use it for real I have:
downloaded datomic-free-0.9.5697
configured my clojure project with lein-datomic 0.2.0 and its instructions.
updated profiles.clj to be:
{:user
{
:java-cmd "C:\\Program Files\\Java\\jdk1.8.0_152\\bin\\java.exe"
:plugins [[lein-datomic "0.2.0"]]
:datomic {:install-location "C:\\Users\\myusername\\.lein\\bin\\datomic-free-0.9.5697"}}}
}
}
but if I now run 'lein datomic start' I get an error:
java.io.IOException: Cannot run program "bin/transactor" (in directory "C:\Users\myusername\.lein\bin\datomic-free-0.9.5697"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
What is wrong with profiles.clj install-location? Is it not working, because the fact I am using Windows. Is there issue with path format?
"bin/transactor" is actually bin folder where transactor and transactor.cmd file exists.
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.
I am trying to compile some Clojure code to Java using the Clojure 1.2 compiler. I am including the Clojure and Clojure-contrib 1.2 jars in the classpath. When I do the compile it fails and I get the folowing error:
Exception in thread "main" java.lang.ClassNotFoundException: clojure.contrib.io.Streams (io.clj:121)
: Has anyone seen this before?
Update:
Here is the line I use to compile my clj files:
java -cp "..\lib\h2.jar;..\lib\vaadin-6.4.4.jar;..\lib\clojure.jar;..\lib\clojure-contrib.jar;..\lib\wlfullclient-10.3.0.0.jar;..\..\..\..\..\jre1.6windows32bit\lib\rt.jar;." -Dclojure.compile.path=cljclasses clojure.lang.Compile oe.main.oe-main
clojure.contrib.io.Streams is a protocol defined in clojure.contrib.io
To help you more you have to share more details about how and what you are trying to compile.
use (compile 'oe.main.oe-main) from a clojure REPL using the same class path, and this works