添加到 Java 类路径会破坏 ant
我希望在我的类路径中包含某个 JAR,以便通过 Jython REPL 轻松访问。所以在我的 .bashrc 中我输入:
export CLASSPATH=:/home/tmacdonald/path/to/jar/thing.jar
但是,这会破坏 ant 编译 JAR 的能力,可以从不同的子包编译 JAR:
$ ant jar
Invalid implementation version between Ant core and Ant optional tasks.
core : 1.8.0 in file:/usr/share/ant/lib/ant.jar
optional: 1.5.1 in file:/home/tmacdonald/path/to/jar/lib/gt2-2.3.3/ant-optional-1.5.1.jar
$ echo $CLASSPATH
:/home/tmacdonald/path/to/jar/thing.jar
更改类路径可以修复它:
$ export CLASSPATH=
$ !ec
echo $CLASSPATH
$ ant jar
[Compiles successfully.]
但必须不断更改我的类路径似乎很尴尬,而且不是正确的事情,取决于我想运行 ant 还是 Jython REPL。我承认我对 ant 和类路径的了解相当薄弱。我只是将类路径视为“Java 库的 PATH;或 Java 的 PYTHONPATH”,并且我只对我继承的现有 ant 配置文件添加了一些小更改——我从来不需要设置一个。
因此,我很想听听到底发生了什么(顺便说一句,这如何导致我的问题),这样我就可以得到更多的教育,当然我也想要一个解决方案。谢谢!
I wanted to have a certain JAR in my classpath for easy access with a Jython REPL. So in my .bashrc I put:
export CLASSPATH=:/home/tmacdonald/path/to/jar/thing.jar
However, this breaks ant both for compiling that JAR can compiling a JAR from a different subpackage:
$ ant jar
Invalid implementation version between Ant core and Ant optional tasks.
core : 1.8.0 in file:/usr/share/ant/lib/ant.jar
optional: 1.5.1 in file:/home/tmacdonald/path/to/jar/lib/gt2-2.3.3/ant-optional-1.5.1.jar
$ echo $CLASSPATH
:/home/tmacdonald/path/to/jar/thing.jar
Changing the classpath fixes it:
$ export CLASSPATH=
$ !ec
echo $CLASSPATH
$ ant jar
[Compiles successfully.]
But it seems awkward and not The Right Thing to have to keep changing my classpath, depending on whether I wanted to run ant or a Jython REPL. I'll admit that my knowledge of both ant and the classpath is pretty weak. I just think of the classpath as being, "PATH for Java libraries; or PYTHONPATH for Java", and I only ever add small changes to existing ant config files I inherited--I've never had to set one up.
So I'd be interested to hear what's really happening (and incidentally how that causes my problem) so I can be a little bit more educated, and of course I'd also like a fix. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 Ant 不应该知道或关心环境变量。正确的方法是在 Ant build.xml 本身内设置 CLASSPATH。
以下是我在 Ant build.xml 文件中使用的生产和测试类路径:
如您所见,没有也不应该有对
${classpath}
的引用。I don't think Ant should know or care about environment variables. The right way to do it is to set CLASSPATH inside the Ant build.xml itself.
Here are production and test classpaths that I use in my Ant build.xml files:
As you can see, there are no references to
${classpath}
, nor should there be.