简体   繁体   English

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

[英]Environment variable CLASSPATH <> Clojure's CLASSPATH. Why?

Here I check the environment variable CLASSPATH 在这里,我检查环境变量CLASSPATH
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ echo $CLASSPATH daniel @ daniel-laptop:〜/ ps / clojure / projects / ring-tutorial $ echo $ CLASSPATH
/home/daniel/ps/clojure/projects/ring-tutorial/src /家庭/丹尼尔/ PS / Clojure的/项目/环教程/ src目录

Here I check what java thinks it is. 在这里,我检查java认为它是什么。
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ lein repl daniel @ daniel-laptop:〜/ ps / clojure / projects / ring-tutorial $ lein repl
Clojure 1.1.0 user=> (System/getProperty "java.class.path") 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:" “SRC /:类/:/首页/丹尼尔/ .m2目录/库/ 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 /公地-IO-1.4.jar:LIB / CLJ-堆栈跟踪-0.1.0.jar:LIB / Clojure的-的contrib-1.1.0.jar:LIB /环devel的-0.2 .0.jar:LIB /码头-util的-6.1.14.jar:LIB / CLJ-HTML-0.1.0.jar:LIB /环码头适配器-0.2.0.jar:LIB /码头-6.1.14的.jar:LIB /环形芯-0.2.0.jar:LIB /公地文件上传-1.2.1.jar:LIB /环servlet的0.2.0.jar:LIB /公地编解码器-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. 我很确定我必须误解我应该在哪里编辑CLASSPATH变量以使java“得到它”,除了我发现的所有内容都说这应该有效。 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. 任何帮助非常感谢。

$CLASSPATH is indeed completely irrelevant here. $CLASSPATH在这里确实完全无关紧要。 It is what java -the-JVM-launcher-programme would use if no classpath information was provided to it on the command line; 如果没有在命令行上为它提供类路径信息,那么java -the-JVM-launcher-program将使用它; Leiningen provides the JVM with a classpath appropriate to whichever project you're working on. Leiningen为JVM提供了适合您正在处理的项目的类路径。

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. 在这种特殊情况下, "/home/.../ring-tutorial/src"对于Ring教程来说不是一个非常有用的类路径,因为它只包含Ring教程的源代码而不包含Clojure jar(这是必要的)对于运行Clojure代码而言,Ring jars(Ring是一个多模块项目)或Ring依赖的任何其他jar。 The classpath produced by Leiningen might seem pretty long, but all of its components really need to be there. Leiningen生成的类路径可能看起来很长,但它的所有组件都需要存在。

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. 顺便说一句,如果你刚刚开始使用Clojure,我建议你坚持使用你的工具链的类路径管理工具(这可能意味着Emacs + lein swank或者某些IDE + Clojure插件),如果可能的话。 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. 否则,关于SO的Clojure类路径问题有很多问题,还有关于你可以google的主题的大量其他资源......但是现在该工具支持非常强大,你通常不需要触及类路径一方面,这只是在开始时最好避免的痛苦。

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. 使用CLASSPATH变量来管理依赖项的问题是,所有Java和其他JVM语言都需要为其目的操作它。 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. 它完全打破了Java开发人员的PC,他有10个程序和项目都需要不同的依赖关系,然后花更多时间调试bash脚本来操作编写源代码的CLASSPATH变量。

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. 因此,管理类路径的这种方式已经被废弃,更喜欢其他类加载技术,或者在使用CLASSPATH时,只在本地使用它。

The Clojure classpath is the Java classpath. Clojure类路径是Java类路径。

$CLASSPATH is ignored when the java executable is invoked with the -cp argument, which Leiningen (and most other Clojure build scripts) do. 使用-cp参数(Leiningen(和大多数其他Clojure构建脚本))调用java可执行文件时,将忽略$CLASSPATH

If you're using a build tool such as Leiningen, you must use it to manage the classpath. 如果您使用的是Leiningen之类的构建工具,则必须使用它来管理类路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM