Clojure with Datomic (lein-datomic) in Windows - clojure

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.

Related

Problems with importing package from Github

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=>

Cursive editor gives classpath exception when trying to run clojure project that uses figwheel

Trying to get a project that uses figwheel running in Cursive. I can get everything running on the command line using run -m clojure.main script/figwheel.clj but when I follow the instructions for running within Cursive I get the following error:
java.io.FileNotFoundException: Could not locate figwheel_sidecar/repl_api__init.class or figwheel_sidecar/repl_api.clj on classpath.
Does anyone know why this works on the command line and not within Cursive? I believe I followed the directions that the project provided. Do I need to set my classpath somewhere in Cursive.

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.

Clojure ring server seems to be missing dependencies on slf4j

I've been trying to follow a number of tutorials on building a web app in Clojure, but I keep running into the same problem. To take the simplest case, I tried following this tutorial: http://drtom.ch/posts/2012-12-10/An_Introduction_to_Webprogramming_in_Clojure_-_Ring_and_Middleware/
When I get to the step that starts the server (run-jetty handler {:port 8383}), I get the following error:
NoSuchMethodError org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple; org.eclipse.jetty.util.log.JettyAwareLogger.log (JettyAwareLogger.java:613)
I asked lien to show me the classpath, and sure enough, org.slf4j.helpers.MessageFormatter isn't in there anywhere.
I've run into this on pretty much every ring-based web tutorial I've tried, so either I've got something configured weird (I updated and reinstalled lein, blew away my ~/.m2 and rebuilt, etc), or something has changed in the myriad dependencies that get put together to make the classpath.
Any ideas what's going on here?
EDIT
I've got further information -- I created a VM in virtualbox, installed OpenJDK and lein, and created a project there. It worked fine. Since I had created it in a directory shared with the host, I then tried doing "lein ring server" in the same directory from the host, and it failed with the above error.
So I did "lein classpath" both in the vm and in the host and compared the results -- they're identical. I also checked that they're running the same build of the same JVM (OpenJDK 64-bit build 24.51-b03).
So, if they're running the same JVM with identical classpaths, what's left?
Can you try updating the dependencies like the following?
(defproject ..........
:dependencies [[org.clojure/clojure "1.5.1"]
[ring/ring-core "1.1.8"]
[ring/ring-jetty-adapter "1.1.8"]
[compojure "1.1.3"]]
:main quickstart.core
:min-lein-version "2.0.0"
:plugins [[lein-ring "0.8.10"]]
:ring {:handler quickstart.core/handler})
If you use the lein ring plugin as configured above, you can start the application like:
lein ring server

Leiningen fails to start a REPL on WinXP machine

I'm using a WinXP (sp3) machine with clojure-1.5.1, leiningen-2.3.4, and the Java 1.7.0_45 jdk. I have no trouble creating a new project with leiningen, starting a clojure shell, or creating and running java programs. However, the following command (please see below) results in the error message(s) displayed. I have added the clojure-1.5.1 and leiningen-2.3.4-standalone.jars to user and system path variables in addition to the creation of a new user and system environmental variable, LEIN_JAR that points to the location of the leiningen.jar file. The classpath for both the user and system variables has also been edited as above. My lein.bat is not missing any double quotes around the location of the LEIN_JAR setting as another poster stated in assisting another beginning(?) user of Clojure. Any constructive help would be appreciated.
My project.clj file :
(defproject test10 "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]])
Edit 2: lein version command output
C:\>lein version
Leiningen 2.3.4 on Java 1.7.0_45 Java HotSpot(TM) Client VM
C:\>lein repl
Error: Could not find or load main class -Dfile.encoding=UTF-8
Exception in thread "Thread-4" clojure.lang.ExceptionInfo: Subprocess failed {:e
xit-code 1}
at clojure.core$ex_info.invoke(core.clj:4327)
at leiningen.core.eval$fn__3532.invoke(eval.clj:226)
at clojure.lang.MultiFn.invoke(MultiFn.java:231)
at leiningen.core.eval$eval_in_project.invoke(eval.clj:326)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:619)
at leiningen.repl$server$fn__7443.invoke(repl.clj:201)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:617)
at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1788)
at clojure.lang.RestFn.invoke(RestFn.java:425)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invoke(core.clj:621)
at clojure.core$bound_fn_STAR_$fn__4102.doInvoke(core.clj:1810)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:744)
REPL server launch timed out.
C:\>
Thank you for the response. The output from lein version looks good. Sorry for the long message :)
Here is my approach to trouble shooting this further. Please make sure you are checking the system logs maintained by Windows. Pertinent messages could be routed to the system logs and not displayed in the console.
So far it appears leinegen can execute, some, but not all of it's commands. If you execute "lein help", you will get list of available commands.
My first thought is, leinegen is having trouble with the "lein repl" defaults. Thus, instead having leinegen choose default values for host and port, set them explictily in the command line. For example: "lein repl :start :host localhost :port 5554" or "lein repl :start :host 127.0.0.1 :port 5554".
I would change in to your "example" directory and verify that "lein deps", "lein check" and "lein compile" all run error free.
Finally, I would edit the example project. Add the following line to project.clj (right after the :dependencies clause)
:main example.core
That line tells leinegen what the entry point of the "example" program is.
Next we need to edit the "src/example/core.clj" file. Delete the contents and replace it with the following "hello word":
(ns example.core)
(defn -main [& args ]
(println "Hello, World!"))
Now, from the root of the example project (C:/>example) run "lein run". Please post the results. If "lein run" succeeds try "lein repl" one more time from the root of the example project.
Again. make sure you check the Window's logs for messages. It might also help to run "lein deps", "lein check" and "lein complile" from the root of the example project. See if any errors are raised that are more helpful.
Sorry I don't use MS Windows. However I have a couple suggestions.
You said you were able to create a new project with leiningen. What disk/directory did you create that project in?
Per your post, it looks like you are issuing the "lein repl" command from the root disk directory of your "c:" drive. Is that where you created a project?
If you change to a different disk/directory, do you get the same error message?
Perhaps leiningen is picking some artifacts it can't resolve in your root directory (I.E. C:/>). Thus, check to see if you can run "lein repl" from a different disk directory.
If you are only getting an error when you running "lein repl" from the root of a project directory, please post some information about the project (E.G. the contents of your project.clj file).
Hope that helps.
Check to make sure that lein is not in a directory whose path has any spaces or capitalized characters in it.
Make sure the JDK is in a directory with no spaces or capitalized characters in it.
Make sure JAVA_HOME is set
Make sure java is in your SYSTEM path