What a source jar is and why you need one
A source jar is a compressed file that holds the original code files for a software library or framework. When you're working in an IDE like Eclipse, IntelliJ, or Visual Studio Code, attaching a source jar lets you read the actual code behind the functions you're using — instead of just seeing the compiled version, which is much harder to understand.
Without a source jar attached, when you hover over a function or try to jump into its definition, your editor shows you nothing useful or tells you the source is not available. With one attached, you can see exactly what the code does, read the comments the developer left, and understand why something works the way it does. This saves hours of guessing.
Key Takeaways
- A source jar file contains the human-readable code for a library, and your IDE needs to know where it is to show you that code.
- You download the source jar from the same place you got the library itself — usually Maven Central, GitHub, or the project's website.
- The process differs slightly between IDEs: Eclipse uses Project Properties, IntelliJ uses Module Settings, and VS Code uses a settings file or extension.
- The source jar filename usually matches the library jar but ends in -sources.jar instead of just .jar.
- If you cannot find a source jar for a library, you can often clone the source code from GitHub and point your IDE to that folder instead.
Finding and downloading the source jar file
The source jar lives in the same repository as the library itself. If you downloaded your library from Maven Central (the most common place), go to search.maven.org and search for the library name. Find the version you're using, and look for a file ending in -sources.jar. Click it to download.
If your library came from a different source — like a GitHub release page or a company's own repository — look for a "Sources" download or a file with sources in the name. Some projects bundle the source jar automatically; others require you to build it yourself from the repository. Check the project's README or documentation if the source jar is not obvious.
Save the source jar file somewhere you can find it again. Many developers keep a lib folder in their project or a dedicated sources folder on their computer. The exact location does not matter as long as you remember where it is.
Attaching the source jar in Eclipse
Right-click your project in the Package Explorer and select Properties. In the left panel, click Java Build Path. Find the library jar in the list under the Libraries tab, click it to select it, then click Edit.
A dialog box opens. You will see a field labeled Source attachment. Click External File and browse to the source jar you downloaded. Select it and click Open. Then click Finish and OK to close the dialogs.
Eclipse will now show you the source code when you hover over functions or press Ctrl+Click to jump into a definition. If it does not work immediately, try closing and reopening the file you are editing.
Attaching the source jar in IntelliJ
Open your project and go to File > Project Structure. In the left panel, click Libraries. Find the library in the list, click it, and look at the right side of the window. You will see a section labeled Source with a folder icon next to it.
Click the folder icon and browse to the source jar file you downloaded. Select it and click OK. IntelliJ will add it to the library entry. Click OK again to close the Project Structure window.
Now when you Ctrl+Click (or Cmd+Click on Mac) a function name, IntelliJ will open the source code instead of the compiled version. If you see a message saying "Source code not found", make sure the source jar filename matches the library version exactly.
Attaching the source jar in Visual Studio Code
VS Code does not have a built-in source jar attachment feature like Eclipse or IntelliJ. Instead, you have two options: use an extension or point your editor to the source code folder directly.
For Java projects, install the Extension Pack for Java from Microsoft. Once installed, open your project settings (Ctrl+Comma or Cmd+Comma on Mac) and search for "source path". You can add the path to your source jar or source folder there. Some extensions like Debugger for Java will also let you attach sources through the debug configuration.
If you have the source code cloned from GitHub instead of a jar file, you can point VS Code to that folder directly. Open the command palette (Ctrl+Shift+P or Cmd+Shift+P), search for "Java: Configure Classpath", and add the source folder path there.
Using GitHub source code instead of a source jar
If you cannot find a source jar for a library, or if you want to see the very latest development version, you can clone the source code from GitHub instead. Go to the project's GitHub page, click the green Code button, and copy the HTTPS or SSH URL.
Open a terminal or command prompt, navigate to a folder where you want to keep the code, and run git clone followed by the URL you copied. This downloads the entire source repository to your computer.
In Eclipse, go to Properties > Java Build Path > Libraries, select your library, click Edit, and under Source attachment click External Folder instead of External File. Browse to the src folder inside the cloned repository. In IntelliJ, use the same Project Structure > Libraries process but select the folder instead of a jar file.
Troubleshooting when source code still will not show
If you attached the source jar but your IDE still will not show the code, first check that the filename is correct. The source jar version number must match the library version exactly. If your library is version 2.5.1, the source jar must be library-2.5.1-sources.jar, not library-2.5.0-sources.jar or library-sources.jar.
Second, try refreshing your project. In Eclipse, right-click the project and select Refresh. In IntelliJ, go to File > Invalidate Caches and restart the IDE. In VS Code, reload the window (Ctrl+Shift+P, then search for "Reload Window").
If the source jar is corrupted or incomplete, try downloading it again from Maven Central or the project's official repository. Some older libraries or less common ones may not have a source jar available at all — in that case, cloning from GitHub is your best option.
Frequently Asked Questions
Do I need a source jar if I am just using a library, not developing it?
No, a source jar is optional for running code. You only need it if you want to read the library's code or debug into it. If you are just calling functions and they work, you do not need one.
Can I use a source jar from a different version of the library?
You can, but it will be confusing because the code you see will not match what your library actually does. Always use the source jar that matches your library version exactly.
What if the source jar is huge and slows down my IDE?
Source jars are usually small because they contain only text. If your IDE feels slow, the problem is probably something else. You can always detach the source jar temporarily by removing it from the library settings and re-attaching it later.
Can I attach source code from a GitHub branch instead of the main release?
Yes. Clone the branch you want (using git clone -b branch-name) and point your IDE to that folder instead of a jar file. This is useful if you want to see code from a development version or a bug fix that has not been released yet.
Why does my IDE show source code for some libraries but not others?
Some libraries include source jars automatically in their Maven repository. Others do not publish them. If a library does not have a source jar, check whether the project is open source and available on GitHub — if it is, you can clone it and use that instead.