# Getting started with jMonkeyEngine and Clojure

"I want to write a 3D game in Clojure! But I don't want to bother with raw OpenGL crap, I had my fill of that with Python and PyOpenGL... And I didn't particularly like Panda3D for Python either. I guess I won't be satisfied until I make my own engine one day. But in the meantime, what's a good engine for Java? I remember hearing years ago about something with monkeys..."

That was my thought process a couple weeks ago, and a swift google reminded me of jMonkeyEngine, or JME for short. I had first heard about it back in 2007 or so, but had never played with it seriously. So I figured, why not? Unfortunately I was under some misconceptions that made the introductory period harder. I'll go over the biggest one quickly. JME is better thought of as a collection of libraries rather than a single jar you dump in your project and start building off of. On top of this collection, JME includes a nice IDE and they really want you to use it all together as part of an SDK platform. I really want to use just vim and the command line and treat their stuff as a library. So immediately I'm at odds with the tool, but no matter, it's not impossible to overcome.

Anyway, let's get started, step-by-step. Create your new clojure project with the lein tool:

$lein new jme_clj Created new project in: /home/kevin/jme_clj Look over project.clj and start coding in jme_clj/core.clj  Now to download a nightly zip from JME's site (don't get the giant SDK, just the collection of libraries). Extract the lib folder into your project's folder. Let's test out importing something! $ lein repl
Copying 1 file to /home/kevin/jme_clj/lib
REPL started; server listening on localhost port 45085
user=> (import com.jme3.app.SimpleApplication)
ClassNotFoundException com.jme3.app.SimpleApplication  java.net.URLClassLoader$1.run (URLClassLoader.java:202) user=>  Hmm, that's no good. What'd it say about copying a file to lib? Let's look in the directory... Heeey, where'd all the other jar files go? Lein uses maven in the backend, and if your deps have changed at all (or it's a fresh project) and you run the repl it will re-acquire the deps after first wiping your lib dir. But after that, if you don't call lein deps directly, you'll be fine storing local jars in there. For a more permanent solution, you have to setup a local maven repository to keep your local jars around in. Also I noticed that lein gave me Clojure 1.3 by default. Clojure 1.4 is out, yo! So I changed my project file and ran lein deps myself, then I re-extracted the JME lib jars. Let's try this again. $ ls lib
clojure-1.4.0.jar  jME3-jogg.jar           j-ogg-vorbisd.jar
eventbus.jar       jME3-lwjgl.jar          lwjgl.jar
jbullet.jar        jME3-lwjgl-natives.jar  nifty-default-controls.jar
jinput.jar         jME3-networking.jar     nifty-examples.jar
jME3-blender.jar   jME3-niftygui.jar       nifty.jar
jME3-core.jar      jME3-plugins.jar        nifty-style-black.jar
jME3-desktop.jar   jME3-terrain.jar        stack-alloc.jar
jME3-effects.jar   jME3-testdata.jar       vecmath.jar
jME3-jbullet.jar   j-ogg-oggd.jar          xmlpull-xpp3.jar