I have a Clojure "main" application that depends on several Clojure libraries, two of which are mine. The compile phase, whether just compiling or running uberjar takes a long time. It's on the order of at least one minute or more. Neither of my libraries nor main are very large.
My libraries' and main project.clj files contain
:aot [bene-cmp.core]
:omit-source true
directives.
What can I do, if anything, to speed up the build process?
Here are the three project.clj files.
project.clj main
;$Log$
;
(defproject bene-cmp "1.0.0-SNAPSHOT"
:description "This is the main benetrak/GIC comparison program."
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/tools.cli "0.1.0"]
[clojure-csv/clojure-csv "1.2.4"]
[seesaw "1.4.0"]
[bene-csv "1.0.0-SNAPSHOT"]
[util "1.0.0-SNAPSHOT"]]
:aot [bene-cmp.core]
:omit-source true
:main bene-cmp.core)
project.clj library 1
(defproject util "1.0.0-SNAPSHOT"
;$Log: project.clj,v $
;Revision 1.3 2012/04/04 18:24:36 cvsuser
;Take II on comments. (comment ) does not work.
;
;Revision 1.2 2012/04/04 18:20:54 cvsuser
;New library for Clojure. Add CVS comments.
:description "A general purposes Clojure library"
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/tools.cli "0.1.0"]]
:aot [util.core]
:omit-source true)
project.clj library 2
(defproject bene-csv "1.0.0-SNAPSHOT"
;$Log: project.clj,v $
;Revision 1.2 2012/04/05 22:50:24 cvsuser
;Update and add cvs logging.
;
:description "A csv parsing library"
:dependencies [[org.clojure/clojure "1.3.0"]
[clojure-csv/clojure-csv "1.3.2"]
[util "1.0.0-SNAPSHOT"]]
:aot [bene-csv.core]
:omit-source true)
setup jvm option -Xmx to 2G or above.
Related
Despite adding the desired dependency to my project.clj file,
(defproject word-tree "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.10.1"]
[org.clojure/clojurescript "1.10.520"]
[clojure-opennlp "0.5.0"] ; <----------------------here
[reagent "0.8.1"]]
...
I am unable to access the functions that the dependency provides.
After referencing the namespace in one of my files,
(ns word-tree.suffix-tree
(:require [clojure.string :as str]
[opennlp.nlp :as nlp])) ; <-----this is the namespace of the dependency
I get this error:
No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"
The weirdest part is that when I run lein deps :tree the dependency shows up!
$ lein deps :tree
...
[cider/piggieback "0.4.1" :scope "test"]
[cljfmt "0.5.7"]
[rewrite-clj "0.5.2"]
[rewrite-cljs "0.4.3"]
[clojure-complete "0.2.5" :exclusions [[org.clojure/clojure]]]
[clojure-opennlp "0.5.0"] <------------------------------------------------here!!!
[instaparse "1.4.9"]
[org.apache.opennlp/opennlp-tools "1.9.0"]
[figwheel-sidecar "0.5.19" :scope "test"]
...
For my project I really want to use this dependency but it's not working. Any advice would be most welcome. Thanks.
It seems to me the problem is that the library is for Clojure on the JVM only, and you are trying to use it on a ClojureScript project.
No such namespace: opennlp.nlp, could not locate opennlp/nlp.cljs, opennlp/nlp.cljc, or JavaScript source providing "opennlp.nlp"
The compiler tried to look for ClojureScript code (extension .cljs) or compatible with both Clojure and ClojureScript (extension .cljc) or plain JavaScript, but found none.
I was trying to pick up Clojure again, but am stumbling right at the beginning. I downloaded lein, and copied the following project.clj and a hello.clj to be absolutely sure that I have a minimal working example.
project.clj:
(defproject hello "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.7.0"]]
:uberjar {:aot :all}
:main hello.core
)
hello.clj:
(ns hello.core
(:gen-class)
)
(defn -main
"This should be pretty simple."
[]
(println "Hello, World!"))
When I run './lein uberjar' I get these warnings:
Warning: specified :main without including it in :aot.
Implicit AOT of :main will be removed in Leiningen 3.0.0.
If you only need AOT for your uberjar, consider adding :aot :all into your
:uberjar profile instead.
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.
Created .../target/hello-0.1.0-SNAPSHOT.jar
Created .../target/hello-0.1.0-SNAPSHOT-standalone.jar
Trying to run this either with ./lein run or with java -jar ./target/hello-0.1.0-SNAPSHOT-standalone.jar results in exceptions:
Can't find 'hello.core' as .class or .clj for lein run: please check the spelling.
Exception in thread "main" java.io.FileNotFoundException: Could not locate hello/core__init.class or hello/core.clj on classpath., compiling:(/private/var/folders/28/bk6d4xj123b0xvsvk91_1jg80009rn/T/form-init1007755193774766954.clj:1:125)
So what is my problem here?
:uberjar {:aot :all} -> :profiles {:uberjar {:aot :all}}
And move hello.clj into ./src/hello directory and rename it to core.clj
using lein for clojure, attempting to use the clojurescript plugin.
followed all readme.md install steps, project.clj has
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "0.0-3126"]]
;; lein-cljsbuild plugin to build a CLJS project
:plugins [[lein-cljsbuild "1.0.6"]]
:hooks [leiningen.cljsbuild]
I cannot seem to get lein to recognize the plugin and am not sure what is being the gremlin.
C:\Functional_Languages\Clojure\clojurescript_master\!work\modern-cljs>lein cljsbuild once
'cljsbuild' is not a task. See 'lein help'.
C:\Functional_Languages\Clojure\clojurescript_master\!work\modern-cljs>lein compile
C:\Functional_Languages\Clojure\clojurescript_master\!work\modern-cljs>lein cljsbuild once
'cljsbuild' is not a task. See 'lein help'.
C:\Functional_Languages\Clojure\clojurescript_master\!work\modern-cljs>lein -v
Leiningen 2.5.1 on Java 1.8.0_51 Java HotSpot(TM) 64-Bit Server VM
C:\Functional_Languages\Clojure\clojurescript_master\!work\modern-cljs>
If you use lein new mies ... for getting the project file, and execute the command, the automatically generated project.clj file should be modified.
This is an example that shows the change:
Before:
(defproject simple "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.122" :classifier "aot"
:exclusion [org.clojure/data.json]]
[org.clojure/data.json "0.2.6" :classifier "aot"]]
:jvm-opts ^:replace ["-Xmx1g" "-server"]
:plugins [[lein-npm "0.6.1"]]
:npm {:dependencies [[source-map-support "0.3.2"]]}
:source-paths ["src" "target/classes"]
:clean-targets ["out" "release"]
:target-path "target")
After
(defproject simple "0.1.0-SNAPSHOT"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.122" :classifier "aot"
:exclusion [org.clojure/data.json]]
[org.clojure/data.json "0.2.6" :classifier "aot"]]
:node-dependencies [[source-map-support "0.2.8"]]
:jvm-opts ^:replace ["-Xmx1g" "-server"]
:plugins [[lein-npm "0.6.1"]
[lein-cljsbuild "1.0.4"]]
:npm {:dependencies [[source-map-support "0.3.2"]]}
:source-paths ["src" "target/classes"]
:clean-targets ["out" "release"]
:target-path "target"
:cljsbuild {
:builds [{:id "simple"
:source-paths ["src"]
:compiler {
:main simple.core
:output-to "out/simple.js"
:output-dir "out"
:optimizations :none
:target :nodejs
:cache-analysis true
:source-map true}}]})
As you see, you need to add lein-cljsbuild plugins with build information. For further explanation, refer to http://www.mase.io/code/clojure/node/2015/01/24/getting-started-with-clojurecript-and-node/
If you don't want the change, just run ./scripts/build.
I think the problem is that your project.clj file is lacking a :cljsbuild stanza/key which defines the various parameters required to compile the clojurescript source files.
Have a look at Modern Clojurescript Tutorial for more details or you can check out my clojurescript file upload example to get an idea of how you can define :cljsbuild targets.
Okay. I'm trying to muck about with twitter4j inside a Clojure REPL, provided by Leiningen. I've specified twitter4j as a build dependency:
(defproject testproject "0.1.0-SNAPSHOT"
:description "Tryin stuff"
:repositories {
"twitter4j" "http://twitter4j.org/maven2"
}
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.6"]
[org.twitter4j/twitter4j-core "3.0.5"]
[org.twitter4j/twitter4j-stream "3.0.5"]]
:plugins [[lein-ring "0.8.8"]]
:ring {:handler testproject.core/app}
:profiles {:dev
{:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]}})
So far, so good. lein deps downloads everything without complaint into the default repo in ~/.m2. Awesome. I fire up the REPL, and I get this and only this:
user=> (import '(org.twitter4j.conf ConfigurationBuilder))
ClassNotFoundException org.twitter4j.conf.ConfigurationBuilder java.net.URLClassLoader$1.run (URLClassLoader.java:202)
The twitter4j jars are all present and accounted for, in ~/.m2/org/twitter4j/twitter4j-core/3.0.5/. Is there... something I don't get about importing Java classes? Some extra config I need to provide?
Try this (the proper package name):
user=> (import '(twitter4j.conf ConfigurationBuilder))
[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.