为 Clojure 项目设置 CLASSPATH
我有一个简单的项目结构:
Base Dir
src ;; Pile of Clojure files
lib ;; Jar files
导出类路径: $ export CLASSPATH=$CLASSPATH:src:lib/*
尝试运行 Clojure 文件: java -cp $CLASSPATH -jar lib/clojure.jar src/wizard-game.clj
但我得到了:
线程“main”中出现异常 java.io.FileNotFoundException:无法在类路径上找到 clojure/contrib/trace_init.class 或 clojure/contrib/trace.clj:
原因:java.io.FileNotFoundException:无法在类路径上找到 clojure/contrib/trace_init.class 或 clojure/contrib/trace.clj:
好的,这是一个类路径问题,但是我在做什么/在哪里错误的?
有没有更好的方法来尝试运行它?
更新:
我尝试了这个命令:
java -classpath $CLASSPATH clojure.main src/wizard-game.clj
现在运行正常。
I have a plain project structure:
Base Dir
src ;; Pile of Clojure files
lib ;; Jar files
To export the classpath:
$ export CLASSPATH=$CLASSPATH:src:lib/*
Trying to run a Clojure file:
java -cp $CLASSPATH -jar lib/clojure.jar src/wizard-game.clj
But I got:
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/contrib/trace_init.class or clojure/contrib/trace.clj on classpath:
Caused by: java.io.FileNotFoundException: Could not locate clojure/contrib/trace_init.class or clojure/contrib/trace.clj on classpath:
Ok, this is a classpath issue but what/where I'm doing wrong?
Is there a better way to try to run it?
UPDATE:
I tried this command:
java -classpath $CLASSPATH clojure.main src/wizard-game.clj
It runs ok now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从关于
-jar
选项的java
手册页中:所以这有点令人失望,但好消息是您可以通过使用不同的启动语法来解决这个问题(参考 clojure.org):
或者,使用 Leiningen 等工具来管理项目的类路径和依赖项!
From the
java
man pages regarding the-jar
option:So that's a bit of a bummer, but the good news is that you can get around this by using a different launching syntax (referenced at clojure.org):
Alternatively, use a tool like Leiningen to manage your project's classpath and dependencies for you!
这是对“如何在 Lein 中运行独立的 Clojure 文件?”的回应。你应该看看lein run。我不确定当前的状态,但有一个独立的 Lein 插件,现在至少有一些(也许是全部)功能默认内置到 lein 中。
尝试在命令行运行 lein help run 以获得快速介绍。
独立的 lein 运行的项目。文档可能会有用。不能 100% 确定它是否与内置的 lein run 匹配,但从我自己的使用情况来看,至少其中一些是匹配的。
https://github.com/sids/lein-run
This is a response to your "How to run a standalone Clojure file in Lein?" you should look at into lein run. I'm not sure the current state but there was a standalone Lein plugin and now there is at least some (maybe all) of the functionality build into lein by default.
Try running a
lein help run
at the command line for a quick introduction.Standalone lein-run project. Documentation may be useful. Not 100% sure if it matches up with the built-in
lein run
but I know from my own usage at least some of it does.https://github.com/sids/lein-run