Reputation: 10672
What is the 'least work' approach to distributing a Clojure application? And is this different from the 'best' approach?
For example here is a trivial 'application' that I want to be able to send to someone:
(doto (javax.swing.JFrame. "Hello World")
(.add (javax.swing.JLabel. "Clojure Distributable"))
(.pack)
(.show))
I imagine it makes a big difference to the answer whether they have Java installed already or not.
Upvotes: 4
Views: 1029
Reputation: 321
The easiest way would be to use Maven, here's what you'll need to do:
Get a copy of Maven 2 installed.
get a copy of the Clojure Maven Plugin, go to its folder and run mvn install
Install clojure.jar into your maven repository by running the following command:
mvn install:install-file -DgroupId=org.clojure -DartifactId=clojure -Dversion=1.1.0-alpha-SNAPSHOT -Dpackaging=jar
-Dfile=clojure.jar
Now you'll need to create a pom.xml which will tell maven how to build your project
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.clojure</groupId>
<artifactId>hello-world</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.1-SNAPSHOT</version>
<configuration>
<sourceDirectories>
<sourceDirectory>src</sourceDirectory>
</sourceDirectories>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.1.0-alpha-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
So now, say you have a hello.clj that look like:
(ns clojure.examples.hello
(:gen-class))
(defn -main[args]
(doto (javax.swing.JFrame. "Hello World")
(.add (javax.swing.JLabel. "Clojure Distributable"))
(.pack)
(.show)))
your project structure should look like:
project/pom.xml
project/src/clojure/examples/hello.clj
if you go to the project folder and run mvn install, it should create project/target/hello-world-1.0.jar which will have a main method, you should be able to run it with
java -cp hello-world-1.0.jar:clojure.jar clojure.examples.hello
You might also want to look into One-Jar project, which would let you bundle both your application and the clojure library in the same jar.
Upvotes: 3
Reputation: 14661
Compile it to byte code and then use Java Web Start (or what every Java installer floats your boat)?
For people without Java installed - Some installed can detect this and fire off the JRE installer. The web JWS does this is some Javascript on the page with the link to the JNLP file. This then will switch the link out for a JRE install link if Java is not detected.
Upvotes: 3
Reputation: 49339
For Mac Os x, java is installed by default and apple provides JarBundler that allows you to turn jars in to native os x applications. OS X applications don't use installers.
For Windows Launch4j is a good choice it will wrap your jar into .exe with an icon also it will check if java is installed if not download it. For a windows installer i recommend NSIS (winamp's installer).
For Linux, jar file + bash script.
Upvotes: 5
Reputation: 3319
Consider Excelsior JET, if you need totally stand-alone app.
Consider some jar-to-exe wrappers, like launch4j.
These advices are for Java platform generally, rather then specifically for Clojure...
Upvotes: 2