Sep 24, 2010

Clojure

Clojure is a dynamic programing language which use the java virtual machine. It directly compile the source code into java bytecode.
Doing projects with leingingen
Leiningen is a simple building tool for clojure. It will make "Build" files for your clojure project.

You can install leniingin by this script. Alsoit will install clojure for you.

http://github.com/technomancy/leiningen/raw/stable/bin/lein

First download the lein file from this. Then,
chmod +x lein
./lein self-install

It will install all the nessesary things.

Now we can create the project. I will create a simple project to display "Hello World". So for do that;

mkdir helloworld
mkdir helloworld/src
touch helloworld/src/helloworld.clj

Then you should edit the helloworld.clj file like this.

(ns helloworld
(:gen-class))

(defn -main [& args]
(println "Hello world"))

Then you must create a file call project.clj in the helloworld directory. That file should contain,

(defproject helloworld "0.1"
:dependencies [[org.clojure/clojure
"1.1.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib
"1.0-SNAPSHOT"]]
:main helloworld)

Now you had complete the source files and project details files. It is time to compile the project.
To compile the project you must type,

$ lein compile
This will compile the project and create lib file which contains all jar files of the project. But we can create a single .jar file for the project. To make it,

$ lein uberjar

This will create two jar files, you can distribute your project with the standalone.jar file.
to run the jar file you must type,

java -jar .jar

No comments:

Post a Comment

Your comments are always welcome ...