How do I attach source code into a project's l

2019-02-27 04:25发布

问题:

I created a simple standalone Spring application in Eclipse as a Java application (and not using maven or gradle). I manually downloaded the needed Spring framework jars, and the application works fine.

Now, I wanted to debug the code and see the flow of code inside the Spring source as well. Hence I downloaded the source code of Spring , as a Zip file. I extracted the source code in a specific location in the file system.

Now, how do I add the Spring source code into the project?

Some of the things that i did are as below:

1) I tried to use the import->existing.. , however it didn't work, as the Spring source are now as Gradle project.

2) During debug, it asks for attaching the source, it works in a way, however it doesn't fulfill what I intend to. Basically I want to debug the code AutowiredAnnotationBeanPostProcessor.java and I want to put the breakpoint on this code. This source belong to the @Autowired annotation and hence I won't be able to attach the source on-the-fly. Hence my intention is to pre place the breakpoint and see how the control goes in there.

Is there any way to attach ALL source code of Spring (i.e., all modules of Spring) to the application being developed (and the application isn't based on maven / gradle).

I did check various SO questions and I didn't get my answer and hence posting new question.

回答1:

First of all, there's nothing to be debuged at @Autowire is just an annotation. The only thing you will see there is its attributes. That's it. The interesting code is in AutowiredAnnotationBeanPostProcessor.java

Anyways, if you want to attach source zips to a jar. In Eclipse is as easy as:

  1. Your Project (Right Click) > Preference
  2. Select Java Build path (Left menu) > Libraries (Tab)
  3. Look for the jar an do click on its arrow
  4. Select source attachement

Here an example of the process.

If you are insterested on how Annotations works. I suggest this tutorial Java Tutorial - Annotations.



回答2:

Do this: Your Project (Right Click) -> Debug As -> Debug Configuration -> Source Tab

or Go to package explorer and right click and Java source attachment.

Or Use maven M2E plugin.



回答3:

  1. if it's a maven project , use "mvn dependency:sources" to download all jar-sources, else download by other way
  2. attach java sources one by one,look pictrue,:) but you will think it's too tired when you have many libraries,you can also use "java source attacher" plugins in eclipse marketplace to attach sources automatic