Javac can't find class that is in the same directory

前端 未结 1 1336
醉话见心
醉话见心 2020-12-18 03:57

I am trying to compile a Java file and I\'m getting this error message:

$ javac -cp \"bc-j-mapi-w-2.4.jar;apache-commons/*;json-org/*;lib/*\" BrightcoveVideo         


        
1条回答
  •  时光取名叫无心
    2020-12-18 04:14

    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
    

    Some notes:

    • . 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.

    0 讨论(0)
提交回复
热议问题