开发者

How to prepare dependencies before playing in a Intellij Idea repl?

开发者 https://www.devze.com 2023-04-05 11:23 出处:网络
Say I want to play with a some clojure library, but insidetheREPL开发者_开发问答 from Intellij Idea. How do I start that REPL prepared? Or for that matter, how I load that library anyway, even after t

Say I want to play with a some clojure library, but inside the REPL开发者_开发问答 from Intellij Idea. How do I start that REPL prepared? Or for that matter, how I load that library anyway, even after the start?


With IntelliJ, library directories inside the project can be included in the Java classpath that's used when starting the REPL. These can then be used in the REPL through Clojure's "use" or "require".

The easiest way to get the libraries into the project is through Leiningen and IntelliJ's Leiningen plug-in. Leiningen is a build and dependency management tool for Clojure.

Download and install Leiningen. Install IntelliJ's Leiningen plugin. Open IntelliJ's setting screen and under IDE Settings > Leiningen, enter the path to the Leiningen executable.

From the IntelliJ project window, create a Clojure file named project.clj in the root. Edit this file using the Leiningen syntax to define the libraries that project depends on. Use the Leiningen library name from the library entry at clojars.org (the main clojure library repository), or the project's webpage.

From the Leiningen plug-in menu, add (+ icon) the project.clj. Now in the Leiningen plugin screen, click the project name to open it's tree, choose the "deps" option, and click the "play" icon from the menu. This will make Leiningen download the libraries, and place them in the correct (/lib) folder of the project.

Now rightclick the project name in the project windows, choose Open Module Settings > Modules > Dependencies > Add > Library > Name (Enter name) > Attach Jar Directories (Choose /lib)

Then start the REPL, load the library with "use" or "require" and you're all set.


I wanted to comment on NielsK's answer, but can not for some reason... anyway make sure that Maven is enabled in the IDE, since leiningen generates a POM that IDEA uses to import the dependencies.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号