Article catalog
1. clojure running separately
As for what clojure is, you can baidu by yourself. In short, it is a program written in Lisp language, compiled into. class and run on the jvm, so you need jre. The independent clojure can be found on the official website. At present, the stable version is 1.8 https://clojure.org/index . After downloading, there is a zip file with a jar clojure-1.8.0.jar, which can run like common jars. In this way, a REPL interactive environment will be obtained. Of course, jre (java8) needs to be pre configured.
https://repo1.maven.org/maven2/org/clojure/clojure/1.8.0/clojure-1.8.0.zip
2. Installing leiningen
This is something similar to maven on clojure. It seems that it essentially integrates maven and uses the configuration file of maven under the current user, but maven itself should not be required. Installing and running Leiningen also does not require pre installing clojure itself.
Installation method 1:
Official website https://leiningen.org/ , there is an installation method above, which is to install and run through a script (lein for linux, or lein.bat for win).
- Using lein.bat self install, the installation error occurs because the jar of lein itself cannot be downloaded. I use proxy in the company, so I need to set up a proxy server. You can add, for example, export HTTPS at the beginning of lein script_ PROXY= http://Username/Password @Format of ProxyServer: port.
- If you still can't download it, you can try to download it directly from leiningen's GitHub, https://github.com/technomancy/leiningen/releases At present, there is version 2.7.1. What you download is a zip. You can change the suffix to jar, and then put it in the corresponding location according to the prompt of message, such as C: / users / ABC /. Lein / self installations / leiningen-2.7.1-standalone.jar. You can also modify the variable of the location of the jar found in lein script to point to the jar. The original text in script is as follows:
By modifying lein_ Home to point to a specific directory, such as export LEIN_HOME="${LEIN_HOME:-"/home/test01/lein"}". Modify lein if necessary_ Point to the jar, or place lein's jar according to its directory name. In this way, lein script will no longer try to download online.
Installation method 2:
Click me to enter the download page , or directly Click me to download Download a. exe windows executable file and use the default configuration during installation. Otherwise, the self installs folder may be missing.
You can learn about leiningen Chinese Course
Run the installed clojure REPL. If there is no accident, it will flash back. If you flash back, run cmd lein -version and you will be prompted to install first. See the prompt for the installation command, but the command can't be executed basically because there is a wall. Follow the next step to install.
Manually configure leiningen
go https://github.com/technomancy/leiningen/releases Download leiningen-2.8.1-standalone.zip, find the lein installation directory installed in the previous step, put it in the self install folder (C: \ users \ Marvin. Lein \ self installs), and change the file suffix to. jar.
Execute lein repl in cmd to enter clojure command line and execute lein repl
Or you can directly search the installed program in the windows start bar and click open.
Further, output a Hello World
[the external chain image transfer fails, and the source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-wkcrauwt-1638189674822) (/ / upload images. Jianshu. IO / upload_images / 4109786-cde910d31fbbe374. PNG? Imagemogr2 / Auto orient / strip|imageview2 / 2 / w / 815 / format / webp)]
3. Use Intellij Idea as the development IED
Installation required Cursive plug-in
Note: if you can't install it online, you can download The zip package of the corresponding version plug-in of your IDE can be imported and installed locally.
As shown in the figure, a new demo project is created locally. You can right-click the. clj file to run it.
code:
(ns firstclojure.core) (defn foo "I don't do a whole lot." [x] (println x "Hello, World!")) (println (foo "Hello Clojure \n"))
It is also convenient to execute code through lein run, but if we want to share our code, we need to generate a jar file. We use lein uberjar to generate jar. The generated jar file is target/uberjar/clojure-noob-0.1.0-SNAPSHOT-standalone.jar. We can run it directly in java.
java -jar target/uberjar/clojure-noob-0.1.0-SNAPSHOT-standalone.jar Hello, Clojure!
More resources can be learned through our company's Clojure website, Clojure learning
4. Running and packaging lein projects
Because third-party packages are used in actual projects, dependency processing cannot be avoided. Using lein to run and package projects is the same as maven. The problem encountered during the test is that jre can't link to lein's official warehouse clojars, prompting the SSL authentication problem. At this time, you can open its home page with a browser, save the certificate of the website as a cer file, and then add it to jre's lib/security/cacerts file, which is jre's default certificate warehouse. Refer to the usage of java keytool for specific steps.
If you specify a private repository in the project.clj file and need to log in, you can add username and password after the repository corresponding to project.clj, such as the following configuration. You can refer to official examples https://github.com/technomancy/leiningen/blob/stable/sample.project.clj , which is mentioned in the notes.
["repo-releases" {:url "http://blueant.com/archiva/internal" :username "abcd" :password "1234"}]
The simple uses of lein are as follows:
lein repl: opens the REPL environment. lein run: run the project. lein uberjar: package the project (cd to the path of project.clj), including dependencies. After getting the jar, it is no different from the ordinary jar.
5. project.clj configuration of leiningen build tool
;;================================================================================ ;;This is a with comments project.clj File. ;;Contains all options. It can be regarded as a configuration sample. ;;Contains "ratio" lein Help tutorial more detailed notes ;;================================================================================ ;; This is a project called "sameple" ;; Group name(Or a company website name or something, group-id)call "org.example" ;; edition(version)by"1.0.0-SNAPSHOT"Project( project) (defproject org.example/sample "1.0.0-SNAPSHOT" ;;In addition to this, you may precede it with backquotes( unquote),or~,Evaluate it( eval). (This note is not very clear to me) ;; This description text is useful for warehouse search (e.g clojars Warehouse) :description "A sample project" :url "http://example.org/sample-clojure-project" ;;Mailing list. There's nothing to say :mailing-list {:name "sample mailing list" :archive "http://example.org/sample-mailing-list-archives" :other-archives ["http://example.org/sample-list-archive2" "http://example.org/sample-list-archive3"] :post "list@example.org" :subscribe "list-subscribe@example.org" :unsubscribe "list-unsubscribe@example.org"} ;;license There's nothing to say about this :license {:name "Eclipse Public License - v 1.0" :url "http://www.eclipse.org/legal/epl-v10.html" :distribution :repo :comments "same as Clojure"} ;;The dependent formats are similar:[group-id/project-name version] ;; classifier : It means that in the same version, for different environments or jdk Used jar,If this element is configured, the element name will be added at the end to find the corresponding jar ;; exclusions : It is used to exclude corresponding repeated dependencies. For example log4j The following contains a.jar. spring.jar Also included a.jar,However, if the two versions are different, you need to exclude one to avoid conflict. :dependencies [[org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"] [org.jclouds/jclouds "1.0-RC6" :classifier "jdk15"] [log4j "1.2.15" :exclusions [javax.mail/mail javax.jms/jms com.sun.jdmk/jmxtools com.sun.jmx/jmxri]]] ;; Dependencies for development phase only. Packaged deployments will not contain these dependencies. :dev-dependencies [[org.clojure/swank-clojure "1.2.1"]] ;; A global dependency exclusion. :exclusions [org.apache.poi/poi org.apache.poi/poi-ooxml] ;;stay project.clj Change or library file directory(:library-path directory)When null, retrieve the dependency. :checksum-deps true ;;Warn if the version is lower than this :min-lein-version "1.3.0" ;; If this option is false,So when you get dependencies, lib The directory will be emptied. ;; If you want lib The directory is not empty, please set it to true :disable-deps-clean false ;; Disable implicit clean :disable-implicit-clean true ;; Delete .class files that do not have a corresponding package in ;; the src/ directory. Workaround for Clojure bug CLJ-322. Causes problems ;; with protocols in upstream libraries; false by default. Set to ;; true to delete all non-project classes or set to a seq of regexes ;; to only delete class files that match one of the regexes. (I think there may be a problem with this translation, so I keep it) ;; non-existent src/Directory, delete all.class file ;; In order to solve Clojure bug CLJ-322, You can set it to true,Or define a regular sequence to delete only mismatched ones class File. :clean-non-project-classes true ;; If :clean-non-project-classes Set to true ;; You can set this regular to keep the matching class File. :class-file-whitelist #"^(org/example|clojure)" ;; stay clean Stage other files will be deleted (except:compile-path and jars/uberjars). ;; %s This symbol will be replaced with the version number of the current project :extra-files-to-clean ["tmp" "sample-%s.tar"] ;; If you can't exactly match the file name you want to delete ;; You can use regular expressions (match file names from the project root) ;; Default to #"^$NAME-.*\.jar$". :regex-to-clean #"hs_err_pid.*" ;; Project checkout route :checkout-deps-shares [:source-path :test-path ~(fn [p] (str (:root p) "/lib/dev/*"))] ;; Load at startup hooks Medium namespaces ;; Hooks Generally from plug-ins, but may also be included in your project source in :hooks [leiningen.hooks.difftest] ;; Predicates to determine whether to run a test or not. See tutorial. ;; Decide whether to run the test. Refer to tutorial :test-selectors {:default (fn [t] (not (or (:integration v) (:regression v)))) :integration :integration :regression :regression} ;; If this is set to true. All and will be loaded leiningen.hooks.*Matching namespaces. ;; Warning!!!: obviously, it will cause too much load dependency, and the startup is slower than the snail :implicit-hooks false ;; (Tips: ahead-of-time (AOT) compiler Is a compiler that compiles ahead of time) ;; gen-class and java The required for interoperability will be compiled in advance.:namespaces It's an alias here ;; Setting a regular will compile all matching :aot [org.example.sample] ;; Pack into jar File entry function ;; set up :skip-aot Metadata is used to do other things. For example, run shell perhaps task. :main org.example.sample ;; stay repl Load this automatically at startup namespace :repl-init sample.repl-helper ;;and:repl-init Same, but it's outdated, so please use it:repl-init. :repl-init-script "src/main/clojure/init.clj" ;; These will be passed on to clojure.main/repl; See their details :repl-options [:prompt (fn [] (print "your command, master? ") (flush))] ;; custom repl Listening port for :repl-port 4001 :repl-host "0.0.0.0" ;; A form to prepend to every form that is evaluated inside your project. ;; Allows working around the Gilardi Scenario: http://technomancy.us/143 :project-init (require 'clojure.pprint) ;; Timeout reconnection. The default is 100 :repl-retry-limit 1000 ;; Warn all reflection calls :warn-on-reflection true ;; Warehouse configuration. Even without configuration, maven The central warehouse will still be searched. :omit-default-repositories true :repositories {"java.net" "http://download.java.net/maven/2" "sonatype" {:url "http://oss.sonatype.org/content/repositories/releases" ;; If a repository contains releases only; setting :snapshots ;; to false will speed up dependency checking. :snapshots false ;; You can also set the policies for how to handle :checksum ;; failures to :fail, :warn, or :ignore. In :releases, :daily, ;; :always, and :never are supported. :releases {:checksum :fail :update :always}} ;; Repositories named "snapshots" and "releases" automatically ;; have their :snapshots and :releases disabled as appropriate. "snapshots" {:url "http://blueant.com/archiva/snapshots" ;; Also supports :private-key and :passphrase. :username "milgrim" :password "locative.1"} "releases" {:url "http://blueant.com/archiva/internal" :username "milgrim" :password "locative.1"}} ;; Development dependent warehouse :deploy-repositories {"releases" {:url "http://blueant.com/archiva/internal/releases" :username "milgrim" :password "locative.1"} "snapshots" "http://blueant.com/archiva/internal/snapshots"} ;; Source file path :source-path "src/main/clojure" ;; Compiled file path :compile-path "target/classes" ; for .class files ;; Required for packaging jar File path :library-path "target/dependency" ; for .jar files ;; Unit test source file path :test-path "src/test/clojure" ;; Profile path :resources-path "src/main/resource" ; non-code files included in classpath/jar ;; Test profile path :dev-resources-path "src/test/resource" ; added to dev classpath but not jar ;; Local dependency lookup path :native-path "src/native" ; where to look for native dependencies ;; Target path :target-dir "target/ " ; where to place the project's jar file ;; Extra classpath :extra-classpath-dirs ["script"] ; more classpath entries not included in jar ;; jar Package name :jar-name "sample.jar" ; name of the jar produced by 'lein jar' ;; same, jar Package name. uberjar Is executable jar package :uberjar-name "sample-standalone.jar" ; as above for uberjar ;; from~/.m2 custom classpath,Instead of copying to:library-path. :local-repo-classpath true ;; java Compilation directory of files :javac-options {:destdir "classes/"} :java-source-path "src/main/java" ; location of Java source ;; Leave the contents of :source-path out of jars (for AOT projects) :omit-source true ;; Matching jar The package will be excluded :jar-exclusions [#"(?:^|/).svn/"] ;; The same thing, only for the needle uberjar :uberjar-exclusions [#"META-INF/DUMMY.SF"] ;; yes jar's manifest Set any key value pair. :manifest {"Project-awesome-level" "super-great"} ;; set up jvm option :jvm-opts ["-Xmx1g"] ;; If your project is a Leiningen Plug in, set this to skip subprocess step :eval-in-leiningen false ;; solve Clojure's agent Thread pool problem. ;; If you see RejectedExecutionException using ;; futures or agents, you may be working with a plugin that doesn't ;; take this workaround into account yet--see the "Threads" section ;; of doc/PLUGINS.md. This key will disable Leiningen's workaround. ;; It may cause some other plugins to fail to exit when they finish. :skip-shutdown-agents true ;; Set up a multi module maven The parent project of the project. :parent [org.example/parent "0.0.1" :relative-path "../parent/pom.xml"]) ;; You can use Robert Hooke to modify behaviour of any task function, ;; but the prepend-tasks function is shorthand that is more convenient ;; on tasks that take a single project argument. ;; You can use Robert Hooke To modify any task The behavior of the function. (use '[leiningen.core :only [prepend-tasks]] '[leiningen.deps :only [deps]] '[leiningen.clean :only [clean]] '[leiningen.pom :only [pom]]) ;; Abbreviated name parameter call (prepend-tasks #'deps clean pom)
reference resources: https://www.jianshu.com/p/27e1fa8fc5cc https://www.cnblogs.com/pekkle/p/6901764.html https://www.iteye.com/blog/clojure-1310586 https://blog.csdn.net/qq_35885488/article/details/96563411