[英]Java Error: bad source file: file does not contain class
The directory of QueryFeatureExtract.java
is like QueryFeatureExtract.java
的目录类似于
gen-java/
└── query_feature
└── QueryFeatureExtract.java
and the java file ThriftClient.java
which use QueryFeatureExtract
is in the same folder with gen-java
, I want to compile Client.java
with 和Java文件
ThriftClient.java
其使用QueryFeatureExtract
与同一个文件夹gen-java
,我想编译Client.java
与
javac -classpath libthrift-0.9.1.jar:slf4j.jar -sourcepath gen-java/query_feature/ ThriftClient.java
Then the error shows 然后错误显示
ThriftClient.java:16: error: cannot access QueryFeatureExtract
QueryFeatureExtract.Client client = new QueryFeatureExtract.Client(protocol);
^
bad source file: gen-java/query_feature/QueryFeatureExtract.java
file does not contain class QueryFeatureExtract
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
1 error
Assuming your files are like this: 假设您的文件是这样的:
./
└── ThriftClient.java
└── gen-java/
| └── query_feature/
| └── QueryFeatureExtract.java
└── libthrift-0.9.1.jar
└── slf4j.jar
And QueryFeatureExtract
begins with the following package declaration: QueryFeatureExtract
从以下包声明开始:
package query_feature;
You should use the following command to compile ThriftClient.java
: 您应该使用以下命令来编译
ThriftClient.java
:
javac -classpath .:libthrift-0.9.1.jar:slf4j.jar:gen-java ThriftClient.java
You can specify folders with -classpath
, you don't need to use -sourcepath
. 您可以使用
-classpath
指定文件夹,而无需使用-sourcepath
。 Don't forget to add .
不要忘记添加
.
to your class path if you have other java files in the current folder. 如果您在当前文件夹中还有其他Java文件,请转到类路径。 To avoid errors since you have a source path containing an other source path, I would recommand moving
ThriftClient.java
into a folder named src
. 为了避免错误,因为您的源路径包含其他源路径,因此我建议将
ThriftClient.java
移动到名为src
的文件夹中。
If it does not work, check that ThriftClient
is importing QueryFeatureExtract
with the correct import: 如果不起作用,请检查
ThriftClient
是否以正确的导入方式导入QueryFeatureExtract
:
import query_feature.QueryFeatureExtract;
看看这个答案 ,您正在编译ThriftClient,请尝试以下操作:
javac -classpath libthrift-0.9.1.jar:slf4j.jar -sourcepath gen-java/query_feature/ *.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.