且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javac找不到同目录下的类

更新时间:2023-09-15 15:10:28

您需要在类路径中包含 .(当前目录):

You need to include . (the current directory) in your classpath:

javac -cp ".;bc-j-mapi-w-2.4.jar;apache-commons/*;json-org/*;lib/*" BrightcoveVideoQueryPOI.java

一些注意事项:

  • . 位于默认类路径中,但如果您使用 -cp 指定显式类路径,则只有在您指定时才会包含它.
  • 此答案的先前版本将 . 添加到类路径的末尾,但 aioobe 说它通常放在最前面,这是有道理的,所以我做了相应的编辑.(按顺序搜索类路径,因此如果您有一个类的两个副本,一个在 . 中,另一个在库中,那么您可能希望 . 版本取代库版本,所以你需要先列出它.当然,一个类的两个不同的副本通常不是一件好事!)
  • 您粘贴的内容看起来像 *nix shell,但您使用的是 ;,这是 Windows 上预期的分隔符.(在 *nix 上,预期的分隔符是 :.)这很可能是正确的,例如如果您使用的是 Cygwin,但我想我会提到它以防万一.
  • . is in the default classpath, but if you use -cp to specify an explicit classpath, then it's only included if you specify it.
  • A previous version of this answer added . to the end of the classpath, but aioobe says that it's typically put first, which makes sense, so I've edited accordingly. (The classpath is searched in order, so if you have two copies of a class, one in . and one in a library, then you probably want the . version to supersede the library version, so you need to list it first. But of course, it's not usually a good thing to have two non-identical copies of a class!)
  • What you've pasted looks like a *nix shell, but you're using ;, which is the separator expected on Windows. (On *nix the expected separator is :.) This may well be correct, e.g. if you're using Cygwin, but I thought I'd mention it just in case.