Apache Thrift依赖问题求助:package org.apache.thrift不存在
Hey there, I know how frustrating it is to sink hours into dependency issues—let’s get this sorted out for you.
First: Does the "Building Java Library........ : no" message matter?
Absolutely. That message means your Thrift installation didn’t compile and install the Java-specific libraries during setup. Without those, even if you’ve added the Maven dependency, your project might struggle to resolve the org.apache.thrift packages correctly (either because the local jar is missing, or version mismatches are causing silent conflicts).
Step-by-Step Fixes
1. Reinstall Thrift with Java support enabled
You’ll need to rebuild Thrift to ensure the Java library is properly compiled:
- Download the Thrift source code matching the version you want to use from the official Apache archives.
- Extract the source, then run these commands in the extracted directory:
./configure --with-java # Enables Java library building make sudo make install - After installation, check if the Java jar exists (usually in
/usr/local/lib/java/thrift-<version>.jaror a similar path). If you see the jar here, that means the Java library was built successfully.
2. Verify your Maven dependency configuration
Double-check your pom.xml to make sure the dependency matches the Thrift version you installed:
<dependency> <groupId>org.apache.thrift</groupId> <artifactId>libthrift</artifactId> <version>YOUR_THRIFT_VERSION</version> <!-- e.g., 0.19.0 --> </dependency>
Then run this command to force Maven to refresh dependencies:
mvn clean install -U
3. Install the local Thrift jar to your Maven repository (if needed)
If Maven still can’t pull the dependency (maybe it’s not available in public repos, or your local build is custom), install the jar you built in step 1 directly to your local Maven repo:
mvn install:install-file \ -Dfile=/path/to/your/thrift-<version>.jar \ -DgroupId=org.apache.thrift \ -DartifactId=libthrift \ -Dversion=YOUR_THRIFT_VERSION \ -Dpackaging=jar
4. Refresh your IDE and project setup
- If you’re using an IDE like IntelliJ or Eclipse, refresh your Maven project (in IntelliJ: right-click the project → Maven → Reload Project; in Eclipse: right-click → Maven → Update Project).
- Make sure any Thrift-generated code in your project is using the correct package references (no typos in
org.apache.thrift).
5. Clean up corrupted Maven cache
Sometimes a corrupted jar in your local Maven repo causes issues. Delete the org/apache/thrift directory from your Maven local repo (usually at ~/.m2/repository/org/apache/thrift), then run mvn clean install -U again to re-download the dependencies.
内容的提问来源于stack exchange,提问作者Raymond Lin

