This is a case of a failure to launch. Namely I am attempting to work through the Enlive tutorial, but have run into the following issue of FileNotFoundException while typing (load "tutorial/scrape1") into the REPL.
I am using the following dependencies
:dependencies [[org.clojure/clojure "1.5.1"]
[enlive "1.1.1"]]
I do the classic steps of lein deps then open the REPL and typing the aforementioned line as the tutorial asks. This is all part of the "Your First Scrape with Enlive..." section of https://github.com/swannodette/enlive-tutorial
Well that are not the only dependencies you need to add to your project.clj. This file needs to look like:
(defproject enlive-tutorial "0.1.0"
:description "Enlive Tutorial"
:dependencies [[org.clojure/clojure "1.5.1"]
[enlive "1.1.1"]
[ring "1.2.0"]
[net.cgrand/moustache "1.1.0"]])
So running lein deps will cause in a long term of downloading dependencies. After this you can just start with the tutorial as presented in the link you just posted.
Maybe it is a good idea just to clone the git repository and follow the instructions they give you to start coding with it:
1. git clone git://github.com/swannodette/enlive-tutorial.git
2. cd enlive-tutorial
3. lein deps
4. lein repl
Related
I have a project where I want certain parts of the code to be able to run on a local environment, and other parts which depend on libraries that only run on a remote environment. E.g.
src/app/core.clj <- can run anywhere
src/app/sandbox/remote_only.clj <- depnds on libs that only function in remote environ
where src/app/core.clj is
(ns app.core
(:gen-class))
(defn -main [] (println "Hello, World!"))
and src/app/sandbox/remote_only.clj is
(ns app.sandbox.remote-only
(:require
[uncomplicate.commons.core :refer [with-release]]
[uncomplicate.neanderthal
[native :refer [dv dge]]
[core :refer [mv mv!]]]))
I want to be able to uberjar and run the code located in core.clj on my local machine without pulling in remote_only.clj which will cause the program to fail locally. According to the docs, Leiningen should be able to accomplish this using profiles and uberjar exclusions e.g.:
(defproject app "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.1"]]
:profiles {:uberjar {:main app.core
:init-ns app.core
:aot :all}
:remote {:init-ns app.sandbox.remote_only
:dependencies [[uncomplicate/neanderthal "0.43.1"]]}} ; these deps will fail locally
:uberjar-exclusions [#".*sandbox.*"]
:repl-options {:init-ns app.core})
compiling the uberjar here will result in:
❯ lein uberjar
Compiling app.core
Compiling app.sandbox.remote-only
Syntax error macroexpanding at (remote_only.clj:1:1).
Execution error (FileNotFoundException) at app.sandbox.remote-only/loading (remote_only.clj:1).
Could not locate uncomplicate/commons/core__init.class, uncomplicate/commons/core.clj or uncomplicate/commons/core.cljc on classpath.
So, explicitly its trying to compile the class that was specifically excluded.
I thought that this kind of problem could be avoided by removing the :all tag from :aot compilation. E.g.:
(defproject app "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.10.1"]]
:profiles {:uberjar {:main app.core
:init-ns app.core
:aot [app.core]}
:remote {:init-ns app.sandbox.remote_only
:dependencies [[uncomplicate/neanderthal "0.43.1"]]}} ; these deps will fail locally
:uberjar-exclusions [#".*sandbox.*"]
:repl-options {:init-ns app.core})
which causes other problems:
❯ lein uberjar
Compiling app.core
Created /Users/warrenronsiek/Projects/app/target/app-0.1.0-SNAPSHOT.jar
Created /Users/warrenronsiek/Projects/app/target/app-0.1.0-SNAPSHOT-standalone.jar
~/Projects/app 5s 15:47:37
❯ java -jar ./target/app-0.1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Var
I've tried playing around with all kinds of :exclusions, :jar-exclusions and regexes. Variations of this question have been asked multiple times (1, 2) Nothing works.
How do I get Leiningen to compile uberjars and ignore the specified file(s)?
You are on the right track with changing :aot :all to :aot [app.core] but when you tried to run the JAR, you are running the library version instead of the whole application version:
java -jar ./target/app-0.1.0-SNAPSHOT.jar
That doesn't include Clojure or any dependencies. You want:
java -jar ./target/app-0.1.0-SNAPSHOT-standalone.jar
I haven't tried this particular setup with the "exclusions" features.
One workaround would be to create sub-projects for the "local" & "remote" parts of your app, which could then be used by a higher-level "total" project.
app
app-local
app-remote
where each of the 3 is a separate Lein project. app-local and app-remote could be developed in isolation. The top-level app project then uses has the 2 sub-projects as dependencies (and therefore only works in the remote/full environment).
The Lein feature checkouts allows you to develop in all 3 repos simultaneously, which is a huge help. It is much faster than the alternative of using lein install, which is slow, manual, repetitive, and error-prone.
P.S. Did you experiment with using lein jar instead of lein uberjar?
I want to use some of the latest features being built frequently at https://github.com/Netflix/RxJava in Clojure, but am having some difficulties getting Leiningen to reference the local .jar that I build. The last version of rxjava released to Clojars was 0.9.0, which I can successfully reach with the following in my projects.clj
:dependencies [[org.clojure/clojure "1.5.1"]
[com.netflix.rxjava/rxjava-clojure "0.9.0"]]
Now, I do a successful build of the current rxjava sources, which produces the following files
/Users/rebcabin/Documents/RxJava/language-adaptors/rxjava-clojure/build/libs/rxjava-clojure-0.9.1-SNAPSHOT-javadoc.jar
/Users/rebcabin/Documents/RxJava/language-adaptors/rxjava-clojure/build/libs/rxjava-clojure-0.9.1-SNAPSHOT-sources.jar
/Users/rebcabin/Documents/RxJava/language-adaptors/rxjava-clojure/build/libs/rxjava-clojure-0.9.1-SNAPSHOT.jar
In my Clojure project directory, I do the following
mvn deploy:deploy-file \
-DgroupId=local \
-DartifactId=rxjava-clojure \
-Dversion=0.9.1-SNAPSHOT \
-Dpackaging=jar \
-Dfile=/Users/rebcabin/Documents/RxJava/language-adaptors/rxjava-clojure/build/libs/rxjava-clojure-0.9.1-SNAPSHOT.jar \
-Durl=file:maven_repository
following the instructions given here: https://gist.github.com/stuartsierra/3062743 (see the bottom) via http://www.pgrs.net/2011/10/30/using-local-jars-with-leiningen/ and leiningen - how to add dependencies for local jars?.
That reports success and produces the following:
$ find maven_repository/
maven_repository/
maven_repository//local
maven_repository//local/rxjava-clojure
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/maven-metadata.xml
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/maven-metadata.xml.md5
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/maven-metadata.xml.sha1
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.jar
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.jar.md5
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.jar.sha1
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.pom
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.pom.md5
maven_repository//local/rxjava-clojure/0.9.1-SNAPSHOT/rxjava-clojure-0.9.1-20130628.172154-1.pom.sha1
maven_repository//local/rxjava-clojure/maven-metadata.xml
maven_repository//local/rxjava-clojure/maven-metadata.xml.md5
maven_repository//local/rxjava-clojure/maven-metadata.xml.sha1
I now fix my projects.clj file to contain the following:
:dependencies [[org.clojure/clojure "1.5.1"]
[com.netflix.rxjava/rxjava-clojure "0.9.1"]]
:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
but lein deps fails to find the local repo
$ lein deps
Could not find artifact com.netflix.rxjava:rxjava-clojure:jar:0.9.1 in central (http://repo1.maven.org/maven2/)
Could not find artifact com.netflix.rxjava:rxjava-clojure:jar:0.9.1 in clojars (https://clojars.org/repo/)
Could not find artifact com.netflix.rxjava:rxjava-clojure:jar:0.9.1 in local (file:/Users/rebcabin/Documents/ClojureProjects/rxjava/expt1/maven_repository/)
This could be due to a typo in :dependencies or network issues.
The following guesses in project.clj also do not work:
:dependencies [[org.clojure/clojure "1.5.1"]
[com.netflix.rxjava/rxjava-clojure "0.9.1-SNAPSHOT"]]
:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
:dependencies [[org.clojure/clojure "1.5.1"]
[com.netflix.rxjava/rxjava-clojure "0.9.1--20130628.172154-1"]]
:repositories {"local" ~(str (.toURI (java.io.File. "maven_repository")))}
any ideas how to proceed, please & thanks?
(I also answered on the mailing list where you asked this)
The groupId in your deploy-file command is incorrect. It should be com.netflix.rxjava. Then in your project.clj, use [com.netflix.rxjava/rxjava-clojure "0.9.1-SNAPSHOT"] for your dependency. Also note that you'll need to do the same with rxjava.core.
from the rxjava project directory run
mvn install
to install the jars to your system's local maven repo.
from your Clojure project's directory add 0.9.1-SNAPSHOT as a dependency and then
lein deps :tree
and make sure you see the correct version used.
I'm new to clojure. I have a jar file I want to play with in a clojure repl, but I've failed to do so with leiningen 2.
I have tried placing the jar file in src/myjar.jar and also in src/org/mydomain/myjar.jar
When I run lein repl I get errors stating that leiningen can not find my artifact, and a reference to a page about repeatability which I do not understand.
Here is my project.clj (with the real name of myjar)
(defproject cljliveordead "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.3.0"]
[org.allen.temporalintervalrelationships/time "0.2" :extension "jar"]])
You can use local jars using the lein-localrepo plugin. Add this line to your project.clj
:plugins [[lein-localrepo "0.4.0"]]
Then install the jar to the local repository using
lein localrepo install <path-to-jar> org.allen.temporalintervalrelationships/time 0.2
You can check that the file is installed by running lein localrepo list and check that lein can resolve the project dependencies using lein deps. If all is well then you can start playing with the jar using lein repl.
Leiningen doesn't like local jars due to its goal of repeatable builds. If this was a real project using a third party closed source jar then the best thing to do is install it in a local Nexus repository and add a reference to that repository to your project.
However, this all seems a bit heavyweight for what you are trying to achieve. If all you want to do is play with the jar in the REPL then create a simple project like this
(defproject clojure-time "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[com.cemerick/pomegranate "0.0.13"]])
and use the pomegranate library to add the jar to your classpath manually
(require '[cemerick.pomegranate :as p])
(p/add-classpath "jsr-310-ri-0.6.3.jar")
(javax.time.Instant/now)
and play away.
the hackish way is to just put it into /proiject/path/lib/ and the 'proper' way is to:
add a dependency for it to your project
run lein deps which will print the command for installing the jar to your local maven repo
run the command leiningen gives you with the path to your jar
run lein deps again
I use clojure-csv in a lot of my applications, so make sure the modules referencing clojure-csv were able to build with it, this is what I did:
0) Ran lein new bene-csv
1) Added this to project.clj (after enter lein new bene-csv). The pertinent line is [clojure-csv/clojure-csv "1.3.2"], but it makes sense to show you the whole project.clj for good example's sake.
(defproject bene-csv "1.0.4-SNAPSHOT"
:description "A csv parsing library"
:dependencies [[org.clojure/clojure "1.3.0"]
[clojure-csv/clojure-csv "1.3.2"]
[util "1.0.2-SNAPSHOT"]]
:aot [bene-csv.core]
:omit-source true)
2) Made sure my bene-csv/src/bene_csv/core.clj references clojure-csv.
(ns bene-csv.core
^{:author "Charles M. Norton",
:doc "bene-csv is a small library to parse a .csv file.
Created on March 8, 2012"}
(:require [clojure.string :as cstr])
(:require [util.core :as utl])
(:use clojure-csv.core))
Finally, I ran these commands, so that my main project could reference bene-csv's functions and defs.
lein deps
lein install
Here's my project.clj:
(defproject hello-world "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:dev-dependencies [[swank-clojure "1.5.0-SNAPSHOT"]]
:plugins [[lein-swank "1.4.3"]])
Leiningen downloads swank-clojure 1.4.0 every time I run lein swank.
(I'm using leiningen 1.7.0)
I don't think you need both the :plugins swank and the :dev-dependencies one.
try with just the dev-dependencies
Assuming you want to always use the same version of swank-clojure (which is also lein-swank),
you can run (for leiningen 1.x):
lein plugin install swank-clojure "1.5.0-SNAPSHOT"
For leiningen 2.x you can add the following to :plugins in the profile.clj file of your lein directory:
[lein-swank "1.5.0-SNAPSHOT"]
and the plugin will be usable from all of your leiningen projects without having to specify the requirement in the project file.
[Mea Culpa I pointed to Clojure 1.3, not Clojure 1.3.0.]
I just downloaded the latest Clojure jar file, 1.3.0. I have a simple cake project, which is now throwing a missing artifact error
1 required artifact is missing.
for artifact:
org.apache.maven:super-pom:jar:2.0
What do I need to add to my project.clj file
(defproject repl-test "0.0.1-SNAPSHOT"
:description "TODO: add summary of your project"
:dependencies [[org.clojure/clojure "1.3"]
[org.clojure/clojure-contrib "1.2.0"]
[clojure-csv/clojure-csv "1.2.4"]
[org.clojure/tools.cli "0.1.0"]
[clj-http "0.1.3"]]
:repositories {"clojure-snapshots" "http://build.clojure.org/snapshots"}
:main repl-test)
or what do I need to build to fetch this missing artifact?
I have made sure the clojure-1.3.0.jar file is installed.
If this is a POM problem, I'm not sure what command to run to install the artifact.
Replace [org.clojure/clojure "1.3"] with [org.clojure/clojure "1.3.0"] then this should work.