Question about debugging Maven projects

If I am debugging a war project, what is the correct way to set a breakpoint in code that is in a dependency? Setting the breakpoint by opening the other project in another window doesn't seem to work.
Thanks.

0
Avatar
Permanently deleted user

You need to have the sources attached for the maven dependency. You have two options, for each of which there are two ways to accomplish them.

Option One
Attach the maven source jar file.

Method A: In the Maven Settings, on the "Importing" settings page select the "Automatically Download Sources" option. Re-import the maven project. Now navigate to the attached source by using Navigate > Class (Ctrl+N) or, when your cursor is on the class or one of its methods in source code, use Navigate > Declaration (Ctrl+B or Ctrl+Click). This will open the source file from the attached source JAR file in your local maven repo. You can then add a breakpoint. With this method, all maven dependencies will have their sources attached (if available in the maven repo). But that can be useful.

Method B: Use Navigate > Class (Ctrl+N) or, when your cursor is on the class or one of its methods in source code, use Navigate > Declaration (Ctrl+B or Ctrl+Click) top open the compiled stub of the class in  question. At the top will be a yellow banner labeled "Sources not  found". Select the "Download Sources" option. With this method, only the sources for the dependency in question are downloaded from the repo and attached.

This option of course assumes you are deploying the source to Maven. But it does end up being the easiest option.


Option Two
Attach the source from you file system (i.e. the other project) to the maven dependency definition. There are two ways to do this:

Method A: Go to File > Project Structure (Ctrl+Alt+Shift+S). Under the Project Settings on the far left pan, select the Libraries page. Find the dependency in question in the middle pane and select it. Then n the right pane, click the plus sign and select "Attach files or directories". Attach the source directory or directories (or a jar/zip file with the sources).

Method B: Use Navigate > Class (Ctrl+N) or, when your cursor is on the class or one of its methods in source code, use Navigate > Declaration (Ctrl+B or Ctrl+Click) top open the compiled stub of the class in question. At the top will be a yellow banner labeled "Sources not found". Select the "Attach Sources" option and attach the source directory.

Now set your break point in the source file (in the current project; not the "parent project of that dependency.)

0

请先登录再写评论。