Eclipse Java debugging: source not found
Quick guide to busting the **"source not found"** ghost in Eclipse:
**Standard/External JAR: π**:
1. Right-click on the offensive JAR and head to **Build Path** -> **Configure Build Path**.
2. The **Libraries** tab carries the JAR. Expand it, find **Source attachment,** and hit **Edit**.
3. **External File/Folder** is your button of choice. Locate the source, hit **OK**, then **Apply and Close**.
**Maven projects (aka the XML jungle)π΄:**
- Put a **<sources>** tag in your **pom.xml**.
- Run that **Maven Update Project** command like you mean it!
**Automatic source-attachment for a carefree life (almost!) π§ββοΈ:**
1. Go to **Window** -> **Preferences** -> **Maven** and checkmark **Download Artifact Sources**.
2. Also, ensure **Download repository index on startup** is selected.
Update Source Lookup paths in Eclipse
Eclipse can be a little stingy when it comes to detecting sources. Give it a hand by updating your Source Lookup paths. Then, restart your debug session for the changes to come into effect.
In a pinch, you can use the "Edit Source Lookup..." command to quickly edit your source lookup paths. Finally, restart Eclipse to apply these changes. This will get Eclipse in line and stop it from throwing "source not found" tantrums!
Debug Information Recompile
If the source and classes are playing the blame game, it might be an issue of misaligned debug information. Recompile your project with debug information (enable the β-gβ option in your JVM compiler settings). This will ensure all information between source and classes aligns like soldiers on parade!
Maven Source Resolution
For those living the Maven life, make sure you're using the M2E plugin. This makes your life easier by autodownloading Maven artifact sources, so you don't have to manually attach each one (imagine the hassle!). Consider this plugin a late-night MVP, saving you from your bleary-eyed stack trace nightmares!
Attaching JDK Source
On some dark debugging days, the standard JDK classes might throw a fit. No worries, you can soothe them by attaching the JDK's source within Eclipse's Java > Installed JREs settings. "But where's the source?", you ask. It should be hanging out within your JDK installation directory, like a Harry Potter with his invisibility cloak!
Classpath Diagnosis
Are your classpath entries acting like a maze? Try running mvn clean eclipse:eclipse
and watch as it solves your maze and creates individual .classpath
entries. Remember the golden rule - your IDE is only as good as your classpath!
Dynamic Source Lookup
Are your sources playing a game of hide-and-seek? Use dynamic source lookup in debug configurations. It's like giving Eclipse a map to navigate your code instead of blindfolded guidance! πΊοΈ
Additional Tips
- **Consistency Check**: like your Grandma's family gatherings, make sure everyone (class sources and runtime versions) is present and playing nice!
- **Automatic Resolution**: it's 2022 - let Maven or your build system handle source attachment. Time to automate, or be obsolete!
- **Debug Thread Context Menu**: in a debug session, itβs a shortcut to your source attachment needs.
Was this article helpful?