cygwin java 测试环境,在Cygwin上运行Java程序-找不到类路径

I have a simple Java program that prints out my classpath. Folder structure is as follows:

[~/tmp/bin]# ls

launcher/ PrintClasspath.class*

And a copy of the same class one more level down in.

[~/tmp/bin/launcher]# ls

PrintClasspath.class*

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/

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/

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

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 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?

解决方案

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/

(via this)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值