I'm trying to run snake.clj
from the Programming Clojure (3rd ed) book examples. Said file starts with this declaration:
(ns examples.snake
(:import (java.awt Color Dimension)
(javax.swing JPanel JFrame Timer JOptionPane)
(java.awt.event ActionListener KeyListener))
(:require [examples.import-static :refer :all]))
(import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN)
; actual program omitted, see above link
Because I'm trying to run this on Windows, and the Clojure CLI Getting Started (recommended by the book) isn't yet available on Windows, I'm using leinigen instead. I've used these instructions to run:
lein repl
from theexamples
folder containing mysnake.clj
file=> (load-file "snake.clj")
But this gives me an error:
CompilerException java.io.FileNotFoundException: Could not locate examples/import_static__init.class or examples/import_static.clj on class path...
Somehow my setup with a repl through leinigen fails to let me use import-static
like that.
As a workaround, I've used WSL Ubuntu to install the Clojure CLI and run it in the root of the book's source code folder, loading the snake file directly using the suggested code in the book ((require '[examples.snake :refer :all])
). That loads just fine, I can even run (game)
from the loaded file, but of course that crashes because WSL Ubuntu has no GUI options (it crashes on an "No X11 DISPLAY..." error).
I would assume that the leinigen-based setup I used failed because I had to do (load-file "import_static.clj")
first. In fact, doing so is a fine workaround because then it all works (after also doing (use examples.snake)
), but this doesn't scale very well for multiple/recursive imports.
What is the proper way to use leinigen (on Windows) to run such scripts? Should I've created a leinigen project file? Or is there a repl-trick to do this?