码迷,mamicode.com
首页 > 其他好文 > 详细

手动编译Clojure

时间:2015-04-13 14:42:22      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:clojure 编译 compile

项目中使用clojure,一般会用leinigin或者maven插件进行编译,官网上对手动编译一笔带过,读起来有点抽象.



clojure环境:

[JW-MacBook]:demo JohnWang$ ll $CLOJURE_HOME

total 9280

drwxr-xr-x@ 14 JohnWang  staff      476  2  3 10:59 ./

drwxr-xr-x  15 JohnWang  staff      510  3 26 14:32 ../

-rw-r--r--@  1 JohnWang  staff     6508  2  3 10:54 build.xml

-rw-r--r--@  1 JohnWang  staff    64207  2  3 10:54 changes.md

-rw-r--r--@  1 JohnWang  staff   962588  2  3 10:54 clojure-1.6.0-slim.jar

-rw-r--r--@  1 JohnWang  staff  3664472  2  3 10:54 clojure-1.6.0.jar

-rw-r--r--@  1 JohnWang  staff     1683  2  3 10:54 clojure.iml

drwxr-xr-x@  3 JohnWang  staff      102  2  3 10:54 doc/

-rw-r--r--@  1 JohnWang  staff    12917  2  3 10:54 epl-v10.html

-rw-r--r--@  1 JohnWang  staff     7754  2  3 10:54 pom.xml

-rw-r--r--@  1 JohnWang  staff    13139  2  3 10:54 readme.txt

drwxr-xr-x@  7 JohnWang  staff      238  2  3 10:54 src/

drwxr-xr-x  10 JohnWang  staff      340  2  3 10:59 target/

drwxr-xr-x@  4 JohnWang  staff      136  2  3 10:54 test/



1.创建工程目录

mkdir demo

cd demo

mkdir src/clj/com/baofeng/data/demo

mkdir classes


classes目录需要手动创建,不创建在之后的编译过程中会报找不到文件的错误,这个目录是*compile-path*的默认目录


2.code

  vi src/clj/com/baofeng/data/demo/test.clj

  代码如下:


    (ns com.baofeng.data.demo.test

    (:gen-class

     :name com.baofeng.data.demo.MainTest))


    (defn -main

       [& args]

       (prn args))


gen-class代表该clojure源文件将生成.class file

name代表生成的.class file的类名


3.启动一个REPL,并进行编译

[JW-MacBook]:demo JohnWang$ java -cp src/clj:/Users/JohnWang/dev/clojure-1.6.0/clojure-1.6.0.jar clojure.main

Clojure 1.6.0

user=>  (compile ‘com.baofeng.data.demo.test)

com.baofeng.data.demo.test

user=> 



4.可以看到classes目录下已生成编译后的.class文件

[JW-MacBook]:demo JohnWang$ ll classes/com/baofeng/data/demo/

total 40

drwxr-xr-x  7 JohnWang  staff   238  4 13 11:51 ./

drwxr-xr-x  3 JohnWang  staff   102  4 13 11:50 ../

-rw-r--r--  1 JohnWang  staff  1831  4 13 11:51 MainTest.class

-rw-r--r--  1 JohnWang  staff   929  4 13 11:51 test$_main.class

-rw-r--r--  1 JohnWang  staff  1357  4 13 11:51 test$fn__4.class

-rw-r--r--  1 JohnWang  staff  1528  4 13 11:51 test$loading__4958__auto__.class


-rw-r--r--  1 JohnWang  staff  2939  4 13 11:51 test__init.class



除了Test外还生成了另外几个.class文件。


5.运行

java -cp classes:/Users/JohnWang/dev/clojure-1.6.0/clojure-1.6.0.jar  com.baofeng.data.demo.MainTest "aaa"






手动编译Clojure

标签:clojure 编译 compile

原文地址:http://blog.csdn.net/palainapplecattle/article/details/45024829

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!