在Cygwin上运行Java程序-找不到类路径 [英] Running Java Program on Cygwin - classpath not found
问题描述
我有一个简单的Java程序,可以打印出我的类路径。文件夹结构如下:
I have a simple Java program that prints out my classpath. Folder structure is as follows:
[~/tmp/bin]# ls
launcher/ PrintClasspath.class*
同级副本又向下一层。
[~/tmp/bin/launcher]# ls
PrintClasspath.class*
当我跳到〜/ tmp
目录并运行 PrintClasspath $ c $时c>在我的
〜/ tmp / bin
目录中,我可以很好地运行该程序,并声明 ./ bin
为
When I jump up to my ~/tmp
directory and run PrintClasspath
in my ~/tmp/bin
directory, I can run the program just fine, stating ./bin
as the classpath.
[~/tmp]# java -cp "./bin" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/
或者我可以运行嵌套在〜/ tmp / bin / launcher
目录,如果我按如下方式编辑类路径:
Or I can run the same file I nested in the ~/tmp/bin/launcher
directory if I edit the classpath as follows:
[~/tmp]# java -cp "./bin/launcher" PrintClasspath
/C:/Cygwin/home/user/tmp/bin/launcher/
但是当我尝试坐在我的〜/ tmp
目录中并尝试在〜/ tmp / bin / launcher
目录中取消我的班级,并以 ./ bin
作为我的班级路径,并在该类通过以下方式定位:
But when I try to sit in my ~/tmp
directory, and try to run my class in the ~/tmp/bin/launcher
directory with ./bin
as my classpath and qualify where the class is located via the following:
[~/tmp]# java -cp "./bin" launcher.PrintClasspath
Error: Could not find or load main class launcher.PrintClasspath
失败。我已经在Linux机器上运行了相同的测试,并且在给一个类路径多个目录后,限定了该类在子目录中的位置,效果很好。
It FAILS. I've run the same test on my Linux box, and qualifying where the class is located in a sub-directory after giving a classpath multiple directories up works fine.
I最初假定这是Windows / Cygwin的细微差别,但是我在Windows命令提示符下尝试了相同的练习,并获得了相同的结果。我在这里缺少什么。我只需要使用完全限定的类路径来运行Windows Java程序吗?
I originally assumed this was a Windows/Cygwin nuance, but I tried the same exercise in Windows command prompt and same result. What am I missing here.do I just have to run my Windows Java programs with a fully qualified classpath?
推荐答案
已解决:什么时候?使用Java的Windows版本在Cygwin中设置类路径,必须使用 cygpath
实用程序以及选项 -wp
来将Unix样式路径转换为Windows路径。
Solved: When setting the classpath in Cygwin using the Windows version of Java, you have to use the cygpath
utility with options -wp
to convert the unix style paths to Windows paths.
[~/tmp]# java -cp `cygpath -wp ./bin` launcher.PrintClasspath
/C:/Cygwin/home/user/tmp/bin/
(通过此)
这篇关于在Cygwin上运行Java程序-找不到类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!