I’ve just installed criterium, and I want to be able to use it from the repl and from other projects. How do I extend the java classpath so that I can use the installed library from anywhere?
I’d appreciate answers that can work easily on all projects I work on in the future. I’m using leiningen, and I would suppose that it would do this when you run lein install, but either I’m doing something wrong or that isn’t enough.
you have to learn basic maven (lein uses maven under the hood) and java classpath mechanics. For a very brief overview:
maven stores dependencies in a hidden directory, .m2, in your home folder. Browse around the folder and it will make sense. When you run
lein installit will put the jar in that folder. Try to find the one you installed. However, most dependencies you use will be on a server like clojars so you shouldn’t need to manually install it into like you did. for example, criterium is here.In your project you need to add criterium as a dependency in project.clj. It will look something like this:
Now cd into the root folder of your project and run
lein deps. This will download the dependencies in project.clj, and automatically put them in .m2 and into the lib folder of your project. To start a repl with the classpath setup runlein replEach project that uses criterium will need to add it as a dependency in it’s project.clj