环境变量 CLASSPATH <> Clojure 的 CLASSPATH。为什么?

发布于 2024-09-17 07:04:57 字数 1015 浏览 6 评论 0 原文

这里我检查环境变量CLASSPATH
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ echo $CLASSPATH
/home/daniel/ps/clojure/projects/ring-tutorial/src

这里我检查java认为它是什么。
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ lein repl
Clojure 1.1.0 用户=> (系统/getProperty“java.class.path”)
“src/:classes/:/home/daniel/.m2/repository/leiningen/leiningen/1.1.0/leiningen-1.1.0-standalone.jar:lib/clojure-1.1.0.jar:lib/servlet-api -2.5-6.1.14.jar:lib/commons-io-1.4.jar:lib/clj-stacktrace-0.1.0.jar:lib/clojure-contrib-1.1.0.jar:lib/ring-devel-0.2 .0.jar:lib/jetty-util-6.1.14.jar:lib/clj-html-0.1.0.jar:lib/ring-jetty-adapter-0.2.0.jar:lib/jetty-6.1.14 .jar:lib/ring-core-0.2.0.jar:lib/commons-fileupload-1.2.1.jar:lib/ring-servlet-0.2.0.jar:lib/commons-codec-1.4.jar:"

正如您所看到的,两个响应完全不同。我很确定我一定是误解了我应该在哪里编辑 java 的 CLASSPATH 变量才能“得到它”,除了我发现的所有内容都表明这应该有效。那么到底是怎么回事呢? leiningen 是否会产生自己奇怪的 clojure 叛徒实例?我是否正在编辑一个完全不相关的变量?非常感谢任何帮助。

Here I check the environment variable CLASSPATH
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ echo $CLASSPATH
/home/daniel/ps/clojure/projects/ring-tutorial/src

Here I check what java thinks it is.
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ lein repl
Clojure 1.1.0
user=> (System/getProperty "java.class.path")
"src/:classes/:/home/daniel/.m2/repository/leiningen/leiningen/1.1.0/leiningen-1.1.0-standalone.jar:lib/clojure-1.1.0.jar:lib/servlet-api-2.5-6.1.14.jar:lib/commons-io-1.4.jar:lib/clj-stacktrace-0.1.0.jar:lib/clojure-contrib-1.1.0.jar:lib/ring-devel-0.2.0.jar:lib/jetty-util-6.1.14.jar:lib/clj-html-0.1.0.jar:lib/ring-jetty-adapter-0.2.0.jar:lib/jetty-6.1.14.jar:lib/ring-core-0.2.0.jar:lib/commons-fileupload-1.2.1.jar:lib/ring-servlet-0.2.0.jar:lib/commons-codec-1.4.jar:"

As you can see, the two responses are completely different. I'm pretty sure that I must just be misunderstanding where I ought to be editing the CLASSPATH variable for java to "get it," except that everything I've found says that this should work. So what's the deal? Does leiningen spawn its own weird renegade instance of clojure? Am I editing a completely irrelevant variable? Any help much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅浅淡淡 2024-09-24 07:04:57

$CLASSPATH 确实在这里完全不相关。如果命令行上没有提供类路径信息,那么 java-JVM-launcher-programme 将使用它; Leiningen 为 JVM 提供了适合您正在处理的任何项目的类路径。

在这种特殊情况下,"/home/.../ring-tutorial/src" 对于 Ring 教程来说不是一个非常有用的类路径,因为它只包含 Ring 教程的源代码,而不包含Clojure jar(运行 Clojure 代码所必需的)、Ring jar(Ring 是一个多模块项目)或 Ring 依赖的任何其他 jar。 Leiningen 生成的类路径可能看起来很长,但它的所有组件确实需要在那里。

顺便说一句,如果您刚刚开始使用 Clojure,我建议您坚持使用工具链的类路径管理工具(这可能意味着 Emacs + lein swank 或某些 IDE + Clojure 插件)(如果有的话)可能的。否则,这里有很多关于 Clojure 类路径问题的问题,以及您可以在 google 上搜索的有关该主题的大量其他资源...但是现在该工具支持非常强大,您通常不需要 /em> 手动触摸类路径,这只是一开始最好避免的痛苦。

$CLASSPATH is indeed completely irrelevant here. It is what java-the-JVM-launcher-programme would use if no classpath information was provided to it on the command line; Leiningen provides the JVM with a classpath appropriate to whichever project you're working on.

In this particular case, "/home/.../ring-tutorial/src" would not be a very useful classpath for the Ring tutorial, since it only includes the Ring tutorial's source and does not include the Clojure jar (which is necessary for running Clojure code), the Ring jars (Ring is a multi-module project) or any of the other jars Ring depends on. The classpath produced by Leiningen might seem pretty long, but all of its components really need to be there.

Incidentally, if you're just starting out with Clojure, I'd recommend you stick to your toolchain's classpath management facilities (that might mean Emacs + lein swank or some IDE + the Clojure plugin) if at all possible. Otherwise, there's a lot of questions on Clojure classpath issues here on SO, plus a multitude of other resources on the topic you can google for... but now that tool support is pretty robust and you don't normally need to touch classpath by hand, it's just pain best avoided in the beginning.

筱果果 2024-09-24 07:04:57

使用 CLASSPATH 变量来管理依赖项的问题是,所有 Java 和其他 JVM 语言都需要对其进行操作以实现其目的。没过多久,你就会把自己逼到角落里。

当您启动仅启动服务器的服务器时,它会起作用。它在 Java 开发人员的 PC 上完全崩溃了,他有 10 个程序和项目,都需要不同的依赖项,然后花费更多时间调试 bash 脚本来操作 CLASSPATH 变量,而不是编写源代码。

因此,这种管理类路径的方法已被废弃,更喜欢其他类加载技术,或者在使用 CLASSPATH 时,仅在本地使用它。

The problem with using the CLASSPATH variable to manage your dependencies is that all Java and other JVM languages would need to manipulate it for their purposes. It does not take long before you have painted yourself in corner.

It kind of works when you start a server which only launches a server. It completely breaks down on a PC of a Java developer, who has 10's of programs and projects all needing different dependencies and is then spending more time debugging bash scripts to manipulate the CLASSPATH variable that writing source code.

Hence this way to manage the classpath has gotten into disuse, prefering other classloading techniques, or when using the CLASSPATH, only using it very locally.

沙沙粒小 2024-09-24 07:04:57

Clojure 类路径是 Java 类路径。

当使用 -cp 参数调用 java 可执行文件时,$CLASSPATH 会被忽略,Leiningen(以及大多数其他 Clojure 构建脚本)就是这样做的。

如果您使用的是 Leiningen 等构建工具,则必须使用它来管理类路径。

The Clojure classpath is the Java classpath.

$CLASSPATH is ignored when the java executable is invoked with the -cp argument, which Leiningen (and most other Clojure build scripts) do.

If you're using a build tool such as Leiningen, you must use it to manage the classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文