Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import a .jar (vaadin-6.4.8.jar) file in a Clojure (.clj) script

Tags:

clojure

vaadin

I need to write a Clojure script to create a simple app by using Vaadin.
In Java I cam use some thing like this.
"import com.vaadin.Application;"
But I don't know how to do it in Clojure. I need to know how to import it and the place I should keep that .jar.

like image 860
Thilina Avatar asked Dec 27 '10 09:12

Thilina


2 Answers

There is a build tool for clojure called leiningen.

  • Follow these instructions to install it: https://github.com/technomancy/leiningen
  • Create a new project
  • Put that jar to lib folder
  • Import classes you need

For example:

(ns your-project-name.core
  (:import (com.vaadin Application)
           (com.vaadin.ui Button Form HorizontalLayout)
           (com.vaadin.data.Property ValueChangeEvent)))

Also read this article on how to use java classes in clojure: http://java.ociweb.com/mark/clojure/article.html#JavaInterop


Note that clojure does not provide a way to import every class in a Java package without specifying each class explicitly: How do I import the entire package but exclude some in Clojure?

like image 67
koddo Avatar answered Oct 03 '22 07:10

koddo


I use Vaadin with Clojure as well and I initially had alot of pain. In the end I made sure I wrote alot of example Vaadin applications using Java only. Once I was familiar with Vaadin I wrote alot of example Clojure applications. Once I was proficient in both then I attempted to use Vaadin with Clojure, and I haven't looked back since.

like image 41
Puneet Shah Avatar answered Oct 03 '22 07:10

Puneet Shah