Could “attach source” be made easier for popular Java libraries?

前端 未结 5 2114
我寻月下人不归
我寻月下人不归 2021-02-11 05:06

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 sit

相关标签:
5条回答
  • 2021-02-11 05:31

    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.

    0 讨论(0)
  • 2021-02-11 05:33

    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.

    0 讨论(0)
  • 2021-02-11 05:35

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

    0 讨论(0)
  • 2021-02-11 05:45

    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

    0 讨论(0)
  • 2021-02-11 05:50

    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.

    0 讨论(0)
提交回复
热议问题