带冒号和不带冒号“:”的 Java 类路径

发布于 2024-12-31 22:30:23 字数 431 浏览 0 评论 0原文

我正在学习Java,我有一个怪癖,我认为只有有经验的人才能回答(我已经经历过SO上类似问题的整个列表)。

在 Eclipse 中编译后从命令行运行时,这是有效的

java -classpath : test.class

,并且不

java test.class

指定目录

java -classpath bin test.class

,而是用冒号指定。

java -classpath bin: test.class

据我所知,

  1. Java 默认情况下检查当前工作目录。
  2. 仅当您指定超过我只有一条路。

I'm learning Java and I have a quirk that I think only someone with experience can answer (I have been through the whole list of similar problems on SO).

When running from command line after compiling in Eclipse, this works

java -classpath : test.class

and this does not

java test.class

nor specifying the directory

java -classpath bin test.class

but specifying with a colon DOES

java -classpath bin: test.class

It was my understanding that

  1. Java checked the current working directory by default
  2. The colon was only used if you were specifying more than one path where I just have one.

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

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

发布评论

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

评论(1

再浓的妆也掩不了殇 2025-01-07 22:30:23

你想运行“java test”而不是“java test.class”

干杯

You want to run "java test" not "java test.class"

Cheers

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