且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Windows XP上从clojure源代码构建jar文件

更新时间:2023-09-19 20:00:34

没有任何工具,你必须手动做一些古怪的步骤。假设您在当前目录中有 clojure.jar ,以及名为 classes 的编译目标文件夹和clojure源使用以下代码在 src / awesome.clj 中创建文件:

Without any tool, you're bound to do some quirky steps manually. Say you have clojure.jar in the current directory, along with a target folder for compilation named classes and a clojure source file in src/awesome.clj with the following code:

(ns awesome)

(defn life-universe-and-everything []
  (println "42"))

为了编译它,您将在命令行上发出以下命令:

In order to compile it you will issue the following commands on the command line:

编辑:使用分号而不是冒号在Windows环境中分离类路径元素

use semicolon instead of colon to separate classpath elements in Windows environments

java -cp clojure.jar;classes;src clojure.main
Clojure 1.3.0
user=> (compile 'awesome)

这将产生编译的类到 classes 文件夹。请注意,如果您的代码依赖于任何库,您需要在启动JVM时修改 -cp 参数值。

This will produce the compiled classes into the classes folder. Please note that if your code depends on any library, you need to adapt the -cp parameter values when starting the JVM.

比使用以下方法创建JAR文件:

Than, you will create the JAR file using:

jar cvf awesome.jar -C classes .

最后,调用您的函数:

java -cp clojure.jar;awesome.jar clojure.main -e "(use 'awesome) (life-universe-and-everything)"

我也建议您阅读官方文件