Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently shipping a desktop Java application. It is a plain old Java 5 Java / Swing app and so far everything worked nicely. Java 5 was targetted because some users were on OS X version / computers that shall never have Java 6 (we may lift this limitation soon and switch to a newer Java and simply abandoning my users stuck with Java 5).

I'm quickly getting up to speed with Clojure but I haven't really done lots of Clojure-to-Java and Java-to-Clojure yet and I was wondering if it was realistic to ship a Clojure desktop application instead of a Java application?

The application I'm shipping is currently about 12 MB with all the .jar so adding Clojure doesn't seen to be too much of an issue.

My plan would be to have Clojure call Java APIs: my application is already divided in several independent jars.

If I understand correctly calling Clojure from Java is harder than calling Java code from Clojure which is why I'd basically rewrite all the UI (part of the UI, mixing Swing components and self-made BufferedImages needs to be rewritten anyway due to the rise of retina display), and do all the 'wiring' from Clojure.

So that's the problem I'm facing: is it realistic to ship a Clojure desktop app? (it certainly doesn't seem to be very widespread but then shipping plain Java desktop apps ain't that common either and I'm doing it anyway)

Technically, what would need to be done? (compared to shipping a Java app)

share|improve this question
Take a look at Seesaw, it is a Clojure DSL for building JVM-based GUI apps (Swing-based). – Michael Klishin Sep 18 '12 at 20:12
Seesaw looks like it may prove useful to build the GUI and do the wiring, but what about the integration of my existing Java APIs / libraries? Should it all be painless? (I'll report here anyway but I'd like to have a bit more feedback before trying to switch to Clojure) – Cedric Martin Sep 19 '12 at 0:15
ClojureScript + (NW.js or Atom Electron) would do the job. – Mario T. Lanza Dec 24 '15 at 20:58

Yes, it is entirely realistic - not many people seem to be doing it yet but I think that is only a matter of time (Clojure is pretty new after all!)

I've personally written an open-source game in Clojure which runs as a Swing application ( so have some experiences to share which may be useful.

  • On average you probably want to have Clojure call into Java APIs. This is mostly common sense - Java has all the great libraries, Clojure is the more productive language for gluing things together.
  • You may want to write a Java-based "loader" with a main(...) method that launches the Clojure part of the code. Among other things, this means that you won't have to AOT compile your Clojure code. Example code here:
  • You will probably want to do things like throw up a splash screen while your application initialises to allow for the extra startup time loading/compiling Clojure code. It probably adds 1-2 seconds to a typical app startup time, which is enough that your user will probably appreciate some feedback. If you are clever, you can actually throw up the whole UI while other stuff loads in the background but this requires some care and might test your concurrency kung-fu :-)
  • You can mix Java and Clojure relatively freely since they can call backwards and forwards fairly transparently. The only complication if you want Java to call Clojure is that Java likes to know the class / interface it is calling at compile time. A good option is to have Clojure code dynamically implement an aleady-compiled Java interface via reify.
  • I've found it pretty easy to develop and package an app in a single jar containing both Clojure and Java code using Eclipse/Maven. The Clojure code can simply be put in src/main/resources and gets loaded / compiled at runtime.
  • You can use Clojure GUI wrappers like seesaw if you like. It seems to be pretty good. I decided against using it, mainly because I wanted to do some fiddly things with Swing directly and didn't feel that I needed an extra layer of abstraction.
share|improve this answer
great answer... +1. Very interesting and thanks for the link to your sourcecode: it shall definitely help. Now I need to get my development environment "stable" (just tried latest leiningen + clojure-mode + nrepl.el and it's not working... yet ; ) – Cedric Martin Sep 19 '12 at 23:58

protected by GlenH7 Dec 18 '13 at 13:12

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.