Javac和java路径不统一,Javac找不到在同一目录中的类

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

BrightcoveVideoQueryPOI.java:57: cannot find symbol

symbol : class BrightcoveAPI

location: class BrightcoveVideoQueryPOI

BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN);

^

BrightcoveVideoQueryPOI.java:57: cannot find symbol

symbol : class BrightcoveAPI

location: class BrightcoveVideoQueryPOI

BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN);

^

BrightcoveVideoQueryPOI.java:57: cannot find symbol

symbol : variable BrightcoveAPI

location: class BrightcoveVideoQueryPOI

BrightcoveAPI brightcoveAPI = new BrightcoveAPI(BrightcoveAPI.PROD_READ_URL_TOKEN);

^

3 errors

This would suggest that javac cannot find the class BrightcoveAPI. I'm not sure what the problem is as it is in the same directory:

$ ls

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值