Mac 上的 Java
我多年来一直在 Windows 上进行 Java 编程,现在才转向 Mac。
我正在运行以下命令,该命令在 PC 上有效,但在 Mac 上无效,我做错了什么。
java -classpath ./lib.patches/*:./lib.core/*:./lib.custom/* test.Test
这给了我一个 ClassNotFound 但 test.Test 位于路径中的一个 jar 中。
感谢您的所有帮助。
好的,我已经进一步调试,当我运行这个命令时,
java -cp . test.Test
我已经解决了!
该脚本是从 PC 复制的,并且以错误的回车符结束该行。
这产生了创建 ClassNotFound 的奇怪结果。
从命令行它可以工作,但从脚本它抛出 ClassNotFound - 一定是 Mac 问题......
I've been programming Java on windows for ages and just moved to the Mac.
I'm running the following command which works on the PC but doesn't on a Mac what am I doing wrong.
java -classpath ./lib.patches/*:./lib.core/*:./lib.custom/* test.Test
This gives me a ClassNotFound but test.Test is in a one of the jars in the path.
Thanks for all help.
OK I've debugged further and when I run this command
java -cp . test.Test
I've worked it out!!
The script was copied from a PC and had the wrong returns to end the lines.
This had the bizarre outcome of creating a ClassNotFound.
from the command line it works but from a script it throws ClassNotFound - must be a Mac issue ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说效果很好。 (转义以表明它与 shell 通配无关,但它可以以任何方式工作。)
lucene-core 位于目录 1 中,lucene demo 位于目录 2 中,或两者都位于单个目录中:
如果您还需要基于当前目录的类文件,您应该显式地将
.
路径添加到类路径中。Works fine for me. (Escaping to show it's not related to shell globbing, but it works either way.)
With lucene-core in directory 1 and lucene demo in directory 2, or both in a single directory:
If you also need class files based off the current directory, you should explicitly add the
.
path to the classpath.验证 @Dave Newton 的结果
使用
ThermometerDemo
,此命令有效:
Verifying @Dave Newton's result, using
with
ThermometerDemo
, this command works:尝试
代替
try
instead