本文介绍了Javac找不到在同一目录中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图编译一个Java文件,我收到此错误消息: $ javac -cp -j-mapi-w-2.4.jar; apache-commons / *; json-org / *; lib / *BrightcoveVideoQueryPOI.java BrightcoveVideoQueryPOI.java:57:找不到符号 symbol:class BrightcoveAPI location:class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^ BrightcoveVideoQueryPOI.java:57:找不到符号 symbol:class BrightcoveAPI location:class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^ BrightcoveVideoQueryPOI.java:57:找不到符号 symbol:variable BrightcoveAPI location:class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^ 3错误 这表明javac找不到类BrightcoveAPI 。我不知道问题是什么,因为它是在同一个目录: $ ls apache-commons bc-j-mapi-w-2.4.jar BrightcoveAPI.class BrightcoveAPI.java BrightcoveVideoQueryPOI.java json-org lib $ b $ $ h $ b javac -cp; bc-j-mapi-w-2.4.jar; apache-commons / *; json-org / *; lib / *BrightcoveVideoQueryPOI。 java 一些注意事项: 。在默认类路径中,但如果使用 -cp 指定显式类路径, 此答案的先前版本在类路径的末尾添加了。,但 aioobe 说,它通常放在第一,这是有道理的,所以我已相应编辑。 (按顺序搜索类路径,所以如果你有一个类的两个副本,一个在。和一个在库中,那么你可能想要 版本,以取代库版本,所以你需要先列出它,但当然,有一个类的两个不完全相同的副本通常不是一件好事!) 你粘贴的内容看起来像一个* nix shell,但是你使用; ,这是Windows上预期的分隔符。 (On * nix,预期分隔符为:。)这可能是正确的,例如。如果你使用Cygwin,但我想我会提到它,以防万一。 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/*" BrightcoveVideoQueryPOI.javaBrightcoveVideoQueryPOI.java:57: cannot find symbolsymbol : class BrightcoveAPIlocation: class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^BrightcoveVideoQueryPOI.java:57: cannot find symbolsymbol : class BrightcoveAPIlocation: class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^BrightcoveVideoQueryPOI.java:57: cannot find symbolsymbol : variable BrightcoveAPIlocation: class BrightcoveVideoQueryPOI BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN); ^3 errorsThis would suggest that javac cannot find the class BrightcoveAPI. I'm not sure what the problem is as it is in the same directory:$ lsapache-commons bc-j-mapi-w-2.4.jar BrightcoveAPI.class BrightcoveAPI.java BrightcoveVideoQueryPOI.java json-org lib 解决方案 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.javaSome 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. 这篇关于Javac找不到在同一目录中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-08 05:08