Sunday, 10 January 2010

Configuring My Development Environment

I'm going for the following configuration:
  1. Use NetBeans to do all the Java / Maven specific stuff.
  2. Use Emacs to do all the Clojure programming.
  3. Use the clojure-maven-plugin to compile the .clj files, and to start the swank server for the project.
If I understand it correctly, this means that I can add dependencies to my pom file, then start up the swank server using "mvn clojure:swank". That will make all the jar files pulled in by Maven available in the Slime repl in Emacs.

I could do all my development in Emacs, but I am unwilling to part with NetBeans. For the pure Java / Maven side, I am very comfortable with NetBeans. This setup gives me the best of both worlds - NetBeans does what it is good at. Emacs does what it is good at.

Let's test this out. I will create a project, add a Jakarta Commons dependency, then try to call it from the repl. Here is the pom:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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>com.nwalex</groupid>
    <artifactid>mrtj-clojure</artifactid>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>mrtj-clojure</name>
    <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <id>build.clojure</id>
            <url>http://build.clojure.org/snapshots</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupid>org.clojure</groupid>
            <artifactid>clojure</artifactid>
            <version>1.1.0</version>
        </dependency>
        
        <dependency>
            <groupid>com.codestuffs.clojure</groupid>
            <artifactid>swank-clojure</artifactid>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupid>commons-lang</groupid>
            <artifactid>commons-lang</artifactid>
            <version>2.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            
            <plugin>
                <groupid>com.theoryinpractise</groupid>
                <artifactid>clojure-maven-plugin</artifactid>
                <version>1.3.1</version>
                <executions>
                    <execution>
                        <id>compile-clojure</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
</pre>
Some things to note:
  1. I added a repository to pick up the clojure dependency
  2. I had to manually install the swank-clojure dependency to my local repository.
If I then start up the swank server with "mvn clojure:swank", I am able to connect to it from Emacs using M-x slime-connect. Now, am I able to access the Jakarta Commons Lang classes?
user> (org.apache.commons.lang.StringUtils/isBlank " ")
true
user> (org.apache.commons.lang.StringUtils/isBlank "not blank ")
false
Yes! That proves the set up.

And does the clojure-maven-plugin compile my .clj files?
neill@korzybski:~/src/mrtj-clojure$ ls target/classes/com/nwalex/mrtj
test$hello_world__3.class  test__init.class  test$loading__6309__auto____1.class
Yes it does.

I am very happy with this. I started down this road yesterday afternoon when I struggled and failed to configure the NetBeans Enclojure plugin to work with Clojure 1.1.0. 1 day later I have a working Clojure development environment integrating NetBeans, Maven, and Emacs. I don't need to mess about with classpaths. Maven will sort all of that out for me when I add dependencies to the pom.

Time to start hacking!

No comments:

Post a Comment