建立Java与Clojure使用蛋糕 [英] Building Java In With Clojure Using Cake

查看:85
本文介绍了建立Java与Clojure使用蛋糕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始编辑:
主要是我想我的Clojure程序使用Java类。



我也有一些好的建议,从蛋糕回到lein,因为他们是
合并。



如果任何人读这篇文章可以建议一本书比设计Java / Clojure构建环境而不是学习Java,我会很感激。
结束编辑:



虽然我可以阅读Java代码,但我不是Java程序员。我使用蛋糕成功构建Clojure主程序,并需要创建一个Java类,它成为我的Clojure主要的一部分。我不知道如何将MyClass.class合并到Clojure构建中。



这里是我的project.clj,后面是几行应用程序.clj文件。

 (defproject ba1-app0.0.1-SNAPSHOT
:descriptionTODO:add summary of your project
:dependencies [[org.clojure / clojure1.2 .1]
[org.clojure / tools.cli0.1.0]]
:main ba2-app)

(ns ba2-app
(:gen-class)
(:use [clojure.string:only [split]]
[clojure.string:only [join]]))

:dynamic avail-trans [\W \D])
(def ^:dynamic acct-types [[\C 0.02] [\S 0.04] [\M 0.06]])



1).java文件是否应该与.clj应用程序模块放在同一目录下? p>

2)构建说明是什么?



谢谢。

解决方案

这不是完全清楚你想做什么。我假设你想编译java类并在你的clojure源中使用。在这种情况下,你不必做一些特别的事情。将你的java类放在你想要的地方(比如说dir'/ project_dir / src')并添加

 :java-source-path   

project.clj 文件。在这种情况下,java类将与clojure文件一起编译,并且其包层次结构根将从您选择的此目录开始。你现在可以使用这些类像你使用任何其他类 - :import (ns ...)形式或直接(import ...)



UPD。也可以提到你可以自由地混合你的java源码目录和你的clojure源,所以你可以有 project.clj 选项:source-path :java-source-part 设置为相同的值src。


Begin Edit: Primarily I want my Clojure program to use a Java class.

I've also gotten some good advice on going back to lein from cake, because they're merging.

If anyone reading this can recommend a book more for setting up a Java/Clojure build environment than learning Java, I would appreciate it. End Edit:

Although I can read Java code, I am not a Java programmer. I am building Clojure main programs successfully using cake, and need to create a Java class that becomes part of my Clojure main. I cannot figure out how to incorporate the MyClass.class into the Clojure build.

First here is my project.clj followed by a few lines of the application .clj file.

(defproject ba1-app "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/tools.cli "0.1.0"]]
   :main ba2-app)

(ns ba2-app
    (:gen-class)
    (:use [clojure.string :only [split]]
          [clojure.string :only [join]]))

(def^:dynamic avail-trans [\W \D])
(def^:dynamic acct-types [[\C 0.02][\S 0.04] [\M 0.06]])
.
.
.

1) Should the .java file go into the same directory as the .clj application module?

2) What would the build instructions be?

Thanks.

解决方案

It is not exactly clear what you want to do. I assume that you want to compile java class and use in your clojure sources. In this case you don't have to do something special. Put your java classes where you want (say, dir '/project_dir/src') and add

:java-source-path "src"

to your project.clj file. In this case java classes will be compiled along with clojure files, and their package hierarchy root will start from this directory you've chosen. You can now use these classes like you woul use any other classes - :import clause in (ns ...) form or direct (import ...).

UPD. It could also be mentioned that you can freely mix your java source directory with your clojure sources, so you can have project.clj options :source-path and :java-source-part set to the same value, "src" in this example.

这篇关于建立Java与Clojure使用蛋糕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆