Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a project in Intellij while setting the breakpoints in another project

I have a (Maven-based) project A loaded in Intellij that has a number of dependencies.

I have the source files of one of those dependencies (say B) in another Intellij project.

I would like to put breakpoints in B and debug project A so that A stops when breakpoints are reached in project B.

In Eclipse, I just need to have both projects in the same workspace and it works. Since there are no workspaces in Intellij, I wonder how to do it, and if it is possible.

like image 711
Ben Avatar asked Apr 11 '16 12:04

Ben


People also ask

How do I debug a breakpoint in IntelliJ?

To do this, go to Settings/Preferences | Build, Execution, Deployment | Debugger and select Drag to the editor or click with middle mouse button. Clicking a breakpoint will then enable or disable it.

Which debugger button do you use to move execution forward to the next set breakpoint?

If you want to go to next break point press F8. Save this answer.

How do I continue debug in IntelliJ?

To continue the program execution after it has been suspended, press F9 or select Run | Debugging Actions | Resume from the main menu.


2 Answers

The other answers sound like they would work, but all I had to do was go to:

Project Structure (Ctrl+Alt+Shift+S)

> Modules

> on the Sources tab for the module that has dependencies, look on the right side,

click the + Add Content Root, then add the src folder of the dependency project.

I was able to then put breakpoints in those src files and IntelliJ would step to them in debugging.

(Note you may see the warning "Alternative source available for the class ...")


Reference

From https://www.jetbrains.com/help/idea/creating-and-managing-modules.html,

"Modules normally have one content root. You can add more content roots. For example, this might be useful if pieces of your code are stored in different locations on your computer."

like image 75
TT-- Avatar answered Nov 15 '22 07:11

TT--


When working with multiple maven projects, I find it convenient to put both under a parent maven project. The two child projects are not aware of the parent and remain independent of each other, but by aggregating them on one parent pom, you can conveniently build and test them at the same time, keeping the dependent in sync with its dependency. When you do that, you can also create Run configurations for each project, launch them in debug mode, and put breakpoints in either or both of them.

The parent pom stays in the parent folder of both projects, and does not need to go into source control because the child poms don't refer to it as their parent--its only for your convenience in working on both at the same time. Such a pom might look like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>anything</groupId>
    <artifactId>anything</artifactId>
    <version>0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>All projects</name>
    <modules>
        <module>project-1-subdirectory</module>
        <module>project-2-subdirectory</module>
    </modules>
</project>
like image 21
Hank D Avatar answered Nov 15 '22 09:11

Hank D