tags:

views:

352

answers:

4

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.

+2  A: 
  1. Consider Excelsior JET, if you need totally stand-alone app.

  2. Consider some jar-to-exe wrappers, like launch4j.

These advices are for Java platform generally, rather then specifically for Clojure...

Vanya
That link doesn't work.
Pinochle
@Pinochle Sorry, corrected the link
Vanya
+3  A: 

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.

Hamza Yerlikaya
+3  A: 

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.

mlk
Hi, would the down-voter mind leaving a note explaining why. Thanks.
mlk
+1 , i see no reason for downvote
Savvas Dalkitsis
+3  A: 

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"&gt;
    <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.

Yogthos