Windows 上的 java -cp 问题

发布于 2024-11-06 09:53:18 字数 1003 浏览 0 评论 0原文

有人可以告诉我为什么 .bat 文件中的这个 java 命令不能在 WinXP 上运行我的 java 程序吗?我将所有 jar 文件放在名为 lib 的文件夹中,将类文件放在包文件夹 mypackage 中。

java -cp ".;.\lib\poi-3.7-20101029.jar;.\lib\jsr173_1.0_api.jar;..." mypackage.MyClassWithMain

我尝试了各种方法都无济于事。当程序尝试使用 jar 文件中的某些类时,我会收到 ClassNotFound 错误。所以,我认为我的 -cp 选项有问题。它确实找到了我的 main()。

我想把这个程序提供给对计算机一无所知的人,所以我希望他们能够双击 .bat 文件并开始使用。

我在 Mac 上写了所有内容,没有太大问题。

我敢打赌主持人会因为这个问题打我的头,但我确实广泛搜索了这个问题的答案。

感谢您! John

抱歉,我应该输入整个命令行:

java -cp “.;.\libs\jsr173_1.0_api.jar;.\libs\poi-3.7-20101029.jar;.\libs\poi-ooxml-3.7-20101029.jar;.\libs\poi-ooxml-schemas-3.7 - 20101029.jar;.\libs\resolver.jar;.\libs\xbean.jar;.\libs\xbean_xpath.jar;.\libs\xmlbeans-qname.jar;.\libs\xmlpublic.jar" excelsifter.ExcelSifterController

这一切都在一行上。我尝试用 / 而不是 \,但这似乎不起作用。我能找到的所有内容都表明,对于 Windows,您必须使用反斜杠。 据我所知,所有依赖项都在这里。至少当我使用基本相同的命令时,我的 Mac 不会抱怨。

包含 .bat 文件的目录包含 excelsifter 包(名为 excelsifter 的文件夹)和包含所有 jar 文件的文件夹 libs。 谢谢,约翰

Can someone please tell me why this java command in a .bat file won't run my java program on WinXP? I have all my jar files in a folder called lib and my class files in a package folder mypackage.

java -cp ".;.\lib\poi-3.7-20101029.jar;.\lib\jsr173_1.0_api.jar;..." mypackage.MyClassWithMain

I have tried all sorts of things to no avail. I get a ClassNotFound error as soon as the program attempts to use some of the classes in the jar files. So, I think there's something wrong with my -cp option. It does find my main().

I want to give this program to someone who doesn't know a thing about computers, so I want them to be able to double-click the .bat file and go.

I wrote everything on a mac without much problem.

I bet the moderator is going to slap me upside the head for this question, but I did search extensively for an answer to this.

Thanks you!
John

Sorry, I should have put in the entire command line:

java -cp ".;.\libs\jsr173_1.0_api.jar;.\libs\poi-3.7-20101029.jar;.\libs\poi-ooxml-3.7-20101029.jar;.\libs\poi-ooxml-schemas-3.7-20101029.jar;.\libs\resolver.jar;.\libs\xbean.jar;.\libs\xbean_xpath.jar;.\libs\xmlbeans-qname.jar;.\libs\xmlpublic.jar" excelsifter.ExcelSifterController

This is all on one line. I tried / instead of \, but that didn't seem to work. Everything I could find on this indicates that for windows you have to use the backslash.
All the dependencies are here, as far as I know. At least my mac doesn't complain when I use essentially the same command.

My directory containing my .bat file contains the excelsifter package (a folder called excelsifter) and the folder libs with all the jar files in it.
Thanks, John

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

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

发布评论

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

评论(1

流星番茄 2024-11-13 09:53:18

您的起始字符串对我来说看起来不错,请尝试检查您使用的库中是否存在其他依赖项(如 @Said 提到的)。最好的方法是搜索你的java找不到的类,可能你会在类路径中未包含的其他库中找到它的声明。

Your starting string looks ok to me, try to check if there are other dependencies in the libraries you use as @Said mentioned. The best way is to search for class your java cannot find, probably you'll find it declaration in some other library you didn't included in your classpath.

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