gpt4 book ai didi

java - 在 Cygwin 上运行 Java 程序 - 找不到类路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:42 25 4
gpt4 key购买 nike

我有一个简单的 Java 程序可以打印出我的类路径。文件夹结构如下:

[~/tmp/bin]# ls
launcher/ PrintClasspath.class*

还有下一层的同一类的副本。

[~/tmp/bin/launcher]# ls
PrintClasspath.class*

当我跳转到我的 ~/tmp 目录并在我的 ~/tmp/bin 目录中运行 PrintClasspath 时,我可以运行程序很好,声明 ./bin 作为类路径。

[~/tmp]# java -cp "./bin" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/

或者如果我按如下方式编辑类路径,我可以运行嵌套在 ~/tmp/bin/launcher 目录中的同一文件:

[~/tmp]# java -cp "./bin/launcher" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/launcher/

但是当我尝试坐在我的 ~/tmp 目录中,并尝试使用 ~/tmp/bin/launcher 目录中运行我的类时./bin 作为我的类路径,并通过以下方式限定类所在的位置:

[~/tmp]# java -cp "./bin" launcher.PrintClasspath
Error: Could not find or load main class launcher.PrintClasspath

它失败了。我在我的 Linux 机器上运行了相同的测试,并且在为类路径提供多个目录后确定类在子目录中的位置工作正常。

我最初认为这是 Windows/Cygwin 的细微差别,但我在 Windows 命令提示符下尝试了相同的练习并得到了相同的结果。我在这里缺少什么。我是否只需要使用完全限定的类路径运行我的 Windows Java 程序?

最佳答案

已解决:当使用 Windows 版本的 Java 在 Cygwin 中设置类路径时,您必须使用带有选项 -wpcygpath 实用程序将 unix 样式路径转换为Windows 路径。

[~/tmp]# java -cp `cygpath -wp ./bin` launcher.PrintClasspath
/C:/Cygwin/home/user/tmp/bin/

(通过 this )

关于java - 在 Cygwin 上运行 Java 程序 - 找不到类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38488352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com