Recently, I’ve been working on a Sudoku game program. Part of the program provides a user with the ability to generate new puzzles of a particular difficulty. Generating a puzzle usually requires two puzzle solvers: one that solves puzzles (slowly) like a human would, the other that solves puzzles (very quickly) like a computer would.
Rather than write my own from scratch, for this part of the development, I wanted to use an existing implementation of the machine-like solver. After a little research (more on this some other time), I found one I liked a lot – the Kudoku solver written in Java from attractive chaos.
But how does one use a local jar file in a Clojure Project? Read on…
Usually when you pull in a dependency for a Clojure program, you would grab it from Clojars or some other repository. But this time, I wanted to use a JAR that exists on my local machine and nowhere else that I know of.
After googling for awhile, I found a lot of misleading (or perhaps outdated) stuff that just didn’t work. So, this post describes what I did that finally got things working.
Before we start, here’s a description of the system I’m using to make all this happen.
- Window 7 Pro, 64-bit
- Java 1.8.0 update 60, 64-bit
- Clojure 1.7.0
- Leiningen 2.5.2
- Maven 3.3.3
So, after making some simple changes to the Kudoku solver (benchmarking tests, simple API, trivial refactorings), I compiled it to a JAR file and gave it a version number in the same form as expected by Leiningen, e.g.
In my main project folder, I created a sub-directory to hold the JAR.
After copying the JAR into the new directory, the next step was to deploy the JAR to the local Maven repository.
This is the step that was most confusing as there is a lot of advice on the web to use
file:file-install rather than
deploy:deploy-file. That didn’t work for my setup for some reason.
Next, some modifications to
project.clj. Here’s what I’m using.
Note particularly the line in the
and the line in the
With these changes in place, a simple
put everything in the right place and the project could be built problem free.
Update: After completing this work, it came to my attention that there is now an even easier way to do this, all in Leiningen. Check out the accepted answer to this question on Stack Overflow.