View sources of used Java classes in IntelliJ Idea

前端 未结 5 2049
借酒劲吻你
借酒劲吻你 2021-02-05 15:08

In visual studio development environment when you use a library if you have the related pdb you can dig into their sources during debug. I wonder is there any way to have this f

相关标签:
5条回答
  • 2021-02-05 15:34

    If you use maven, there is a button "Download sourcec" on maven panel.
    If you don't, you need to get sources of hibernate first, search on the internet. And then attach them: File -> Project Structure -> Libraries -> Your hibernate lib -> and attach source

    0 讨论(0)
  • 2021-02-05 15:40

    Of course, quoting the documentation:

    Libraries may optionally include the source code for the library classes as well as corresponding API documentation. [...] However, it adds the ability to use inline documentation extracted from the source code, and also to view the API documentation right from the IDE.

    The documentation doesn't mention you can then debug external libraries, which is obviously also possible.

    In order to add sources choose:

    • File | Project Structure
    • Click Libraries tab
    • Pick library and click + icon
    • Find a JAR file containing sources.

    If you are using build tool like maven, IntelliJ will automatically download and attach available source to all libraries, no manual work needed.

    0 讨论(0)
  • 2021-02-05 15:46

    In my case, I had to add the JDK source files to the project as below.

    Go to Project Structure -> SDKs -> Sourcepath

    Use the Plus Sign on the right, and provide the path to your $JAVA_HOME/src.zip file.

    0 讨论(0)
  • 2021-02-05 15:55

    Project Structure | Libraries (or Module Dependencies if libraries are defined there):

    Project Structure

    Then in the libries tab click on the plus mark:

    Libraries

    Select the source type:

    Add source

    Then you have to select the source path and add the wanted libraries finally click apply!

    0 讨论(0)
  • 2021-02-05 15:58

    Go toImplementation(s)

    No one suggested the simple route with a context-menu:

    1. import java.util.DesiredClass
    2. select this import statement
    3. right click -> Go to -> Implementation(s)

    Done! The source code of the DesiredClass opens in a new tab.

    This also works with selected class name in the body of your code.

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