1

The directory of QueryFeatureExtract.java is like

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

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
2
  • What is the package declaration of QueryFeatureExtract ? Shouldn't you use -sourcepath gen-java/ instead of gen-java/query_feature/ ? Commented Jan 29, 2018 at 9:11
  • @Raphaël Use this, it will show error package QueryFeatureExtract does not exist.. the package declaration of QueryFeatureExtract is "package query_feature;" Commented Jan 29, 2018 at 9:15

2 Answers 2

2

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:

package query_feature;

You should use the following command to compile 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. Don't forget to add . to your class path if you have other java files in the current folder. 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.

If it does not work, check that ThriftClient is importing QueryFeatureExtract with the correct import:

import query_feature.QueryFeatureExtract;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! It works! BUT the another error "Error: A JNI error has occurred, please check your installation and try again". Is this related to Class QueryFeatureExtract?
JNI means that your Java code is calling a C or C++ library. The library may have crashed or you may have path problems when launching your app. Since I don't now which file is using JNI, I can't tell you if it is related to QueryFeatureExtract.
0

Take a look this answer, You are just compiling ThriftClient, try this:

javac -classpath libthrift-0.9.1.jar:slf4j.jar -sourcepath gen-java/query_feature/ *.java

4 Comments

@danche notice the star (*.java) at the end
@danche I thought your problem was QueryFeatureExtract.java? Dont you want to compile this class too?
Yes, But it is same after compile it or not...when I put the ThriftClient.java under gen-java/query_feature, it will cause package QueryFeatureExtract does not exist error.. very confused...
@danche my bad i thought Thrift and Query classes is in same package

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.