Eclipse中import org.apache无法解析错误求助(Hadoop 2.6.0)
Hey there! Let's break down why you're hitting this unresolved import issue and walk through the fixes step by step.
First, a quick reality check: the steps you took so far (placing hadoop-2.6.0.jar in Eclipse's plugins directory and setting 777 permissions) aren't necessary for project dependencies—Eclipse doesn't look for your project's jars in the plugins folder, so that move didn't help and might even cause conflicts later. Let's focus on the actual root causes and fixes:
Common Causes & Solutions
1. You're Missing Critical Hadoop Dependencies
Hadoop 2.x isn't a single jar—it's a collection of core jars and dozens of third-party dependencies. Just adding hadoop-2.6.0.jar (which I suspect is the main core jar) isn't enough to resolve all org.apache.hadoop imports.
Fix:
Grab all the necessary jars from your extracted Hadoop 2.6.0 directory:
- Navigate to
<your-hadoop-extracted-dir>/share/hadoop - Add these jars and their
libsubfolder jars to your project's build path:commondirectory:hadoop-common-2.6.0.jar+ all jars incommon/libmapreducedirectory:hadoop-mapreduce-client-core-2.6.0.jar+ all jars inmapreduce/libhdfsdirectory:hadoop-hdfs-2.6.0.jar+ key jars inhdfs/lib(like commons-*, guava, etc.)yarndirectory (if you're using YARN): relevant core jars + their libs
2. Eclipse Hasn't Refreshed or Recognized Your Build Path Changes
Sometimes Eclipse needs a nudge to pick up new dependencies, especially if you added jars while the project was open.
Fix:
- Right-click your project →
Refresh - Go to
Build Path→Configure Build Path→Librariestab- Check for any red exclamation marks next to jars—this means the path is invalid. Re-select the correct jar location if needed.
- Confirm all the Hadoop jars you added are listed here, then click
Apply and Close
3. JDK Version Mismatch
Hadoop 2.6.0 is compiled with JDK 1.7, so if your Eclipse project is using a newer JDK (like 1.8+), you might run into compatibility issues that manifest as unresolved imports.
Fix:
- Right-click your project →
Properties - Go to
Java Build Path→Libraries- Select
JRE System Library→ clickEdit→ chooseAlternate JREand point to JDK 1.7
- Select
- Switch to the
Java Compilertab- Set
Compiler compliance levelto 1.7 → clickApply and Close
- Set
Step-by-Step Quick Fix Guide
- Clean up the unnecessary jar: Remove
hadoop-2.6.0.jarfrom/opt/eclipse/plugins—this directory is for Eclipse plugins, not project dependencies. - Add all required Hadoop jars: Follow the steps under "Missing Critical Dependencies" to add all relevant jars to your project's build path.
- Refresh and validate: Refresh your project, double-check the build path for invalid jar paths, and confirm JDK 1.7 is configured.
- Test your imports: Open your MapReduce class—your
import org.apache.hadoop...statements should now resolve without errors.
内容的提问来源于stack exchange,提问作者Joy

