Could "attach source" be made easier for popular Java libraries?

I run into this obstacle when my debugger steps into some classfile without corresponding source. Finding it is often difficult:

  • You have to search for the site hosting the respective project, and find its ``download source'' page (for instance, last time I searched for the JPA API, and it took me hours to obtain the sources). Or, you might be required to check it out from revision control.

  • You need to know the exact version you are using. Otherwise the debugger might step into comments and empty lines :)

  • There is no convention for packaging source code—some projects include it in the jar itself; some provide a separate zip file; others put it in a src/ subfolder within the zip.

I know Maven has the capability of downloading source from its repository and including it in the src paths when an IDE config file is generated. But Maven's repo is so poor in terms of content—few libs actually have their source uploaded.

Why is it so complicated when it can be made straightforward? We could have some central repo which relates a classfile (or a hash thereof) to the source file it was compiled from (or a link to it). Maybe a rather huge repo, but pretty simply structured. An IDE plugin could query it to fetch what's needed automatically.

Have you, guys, experienced the same?

How do you obtain the sources to attach?


Asked by: Kellan622 | Posted: 28-01-2022






Answer 1

Both m2eclipse and IDEA will download the sources and javadocs for any dependencies. The m2eclipse sources can be downloaded by right-clicking on a dependency (or the whole project if you want all sources) and clicking Maven->Download Sources.

download sources screenshot

On newer versions of m2eclipse you can also automatically download sources by going to Window->Preferences...->Maven, then selecting the "Download Artifact Sources" option. When you open a type in a dependency jar that there are currently no sources available for, Maven will download the sources in the background and update the source attachment in the background.

Maven preferences screenshot

Answered by: Julian650 | Posted: 01-03-2022



Answer 2

Haven't seen a satisfactory solution myself.

I tend to roll my own repo, without Maven (Maven is fine, but it doesn't click with me). I run something similar to the BSD ports system, that is, one big structured tree that contains little Ant build files. These build files either checkout the source of a project, pull its dependencies from somewhere else in the tree and build it (these are for the projects I want to build- i.e., mine) or pull binaries from somewhere else (which might be an external source or my own binaries repository).

The system could easily be extended to pull src jars, but I do that manually now.

Answered by: Brad101 | Posted: 01-03-2022



Answer 3

it may be complicated but it is worth the initial effort.

i do it the following way: in my project directory i have three major directories,

  • src (my own)
  • lib
  • suppl (sources / javadocs when no sources exist)

i put in suppl one zip file per library, containing the sources. in intellij this gives me not only debugger superpowers, but also javadocs.

you are right, obtaining the sources is a pain. sometimes the sources come deliveded in the .jar file of the lib, sometimes as a seperate download (my favorite) and sometimes i have to create a seperate cvs/svn dir where i can checkout the sources. i usually need to re-package them the way i like them, even if provided in a zip.

i am sceptical about maven. i just don't like to hand over my decisions about choosing libs to a program.

Answered by: Hailey171 | Posted: 01-03-2022



Answer 4

we do something similar to Andreas. Our lib directory has subdirectories categorizing further. One such sub dir is source or debug which has the source JAR/ZIPs of all the jars that we want to debug. Do it once and you're good. We use an IVY repository for the jars and source jars.

Answered by: Anna305 | Posted: 01-03-2022



Answer 5

This is all done automatically if you use M2eclipse (http://m2eclipse.sonatype.org).

Answered by: Ada135 | Posted: 01-03-2022



Similar questions

java - Debugging external libraries, without modifying them, under tomcat

We have a web application which sometimes (quite rarely, several times a day) gives an error in production. It is deployed on Tomcat, uses Spring+Hibernate, the error is caused by a Hibernate exception which is hard to understand without actually logging the parameters passed to the method of the Hibernate class. It is not possible to replace the Hibernate library with a modified version which logs the parameters, and spri...


java - Debugging Android SDK libraries

I would now like a way to step through the SDK libraries (both C and Java code) to pinpoint exactly what is going on. So far, I have installed the NDK and gotten GDB up and running. I am able to attach to the process. I've tried bt and strace but that doesn't provide any useful information. What do I need to do to be able to step into the Java code from the SDK (and the native C...


java - Why doesn't debugging work when using Guava libraries in Eclipse?

When I debug and the marker goes to the point to use Guava, the whole debugging session crashes. It says that no source attachment was found for Guava. How do I fix this problem?


Java swing UI crash debugging

I am trying to debug a problem where a user clicks on the button and the UI just dies. I know, good luck. The logs just end after the user clicks the button so i'm thinking there may be some exception/error that we are not logging. Maybe an OutOfMemoryError. Any suggestions on how to proceed? to get more information. Java command setting etc. Thanks for any help rich


java - JBoss debugging in Eclipse

How do you configure JBoss to debug an application in Eclipse?


java - Debugging JVM crashes under Windows

I wrote a piece of software in Java that communicates with USB hardware by using a DLL provided by the hardware vendor. I used the Java Native Access library to write the wrappers to native code. Sometimes when I am running it, only on native code related functions, JVM crashes and I cannot find what caused the bug because it happens in native code, to which I...


java - Struts tiles visual debugging

At a previous job they had a debug mode that would highlight struts tiles in the browser so you could tell what each tile was doing and the tile's filename. This was enormously helpful for when you are lost in a forest of nested tiles. Now that I'm at a new struts place, I've been trying to figure out how to implement it but I'm coming up empty. Any ideas?


debugging - Java appears hung

I've been using the Java Service wrapper in a custom application for quite a while and it's been working fine. Since updating our application to a new version in the last few days the JVM started hanging and then wrapper prints this in the log: JVM appears hung: Timed out waiting for signal from JVM. It then automatically terminates the JVM and starts the app again. This happens after about 10 hours of running, wh...


debugging - Use NetBeans to inspect live Java objects?

In Python, I'm used to being able to start a debugger at any point in the code, then poke around at live objects (call methods, that sort of thing). Is there any way, using NetBeans, to do this? For example, I'd like to be able to break at the line foo = bar().baz().blamo() and run bar(), bar().baz() and bar().baz().blamo() to see what they do. In Python,...


java Swing debugging headaches with Wacom pen tablet

I've been running up against a problem with Java Swing + my Wacom Graphire tablet for a few years in several Java applications and have now encountered it in my own. I use a pen tablet to get around wrist issues while clicking a mouse, and it works fine under Windows except when I'm using Java applications. In Java applications, the single-click of the pen doesn't work correctly. (Usually the problem only occurs wi...


java - Why does the debugged program slow down so much when using method entry debugging?

I'm using jdi interfaces to create a debugger and when I use MethodEntryRequests to enable method entry tracing the debugged program slows down by factor of tens. I have set filter for main thread and suspend policy to SUSPEND_EVENT_THREAD. Classfilter is limited and if I print any received events it doesn't show more than couple of dozen of those so it shouldn't receive too much of them. I'm debugging locally and having f...


java - Print methods not called when running, called when debugging

I created a class with four methods. I inserted print statements into them, so I could see if they work properly. There is no problem with the first three. But when I call the fourth method nothing prints out. Strangely when I initiate debugger and move through the method step by step, the statements are called(and output printed). How can this be? Thanks in advance. Method in question: p...


debugging - How do you debug Java Applets?

Currently, the only information I have is a one-line error message in the browser's status-bar. Do you know how I could get a stack-trace for example ?






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top