如何在Intellij中调试项目,同时在另一个项目中设置断点 [英] How to debug a project in Intellij while setting the breakpoints in another project

查看:2054
本文介绍了如何在Intellij中调试项目,同时在另一个项目中设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个(基于Maven的)项目,在Intellij中加载了一些依赖关系。 b)在另一个Intellij项目中。



我想在B中设置断点并调试项目A,以便在项目B中达到断点时,A停止。

在Eclipse中,我只需要在同一个工作区中同时使用这两个项目,并且它可以工作。因为Intellij中没有工作区,我想知道如何做到这一点,如果可以的话。

解决方案

在maven项目中,我发现将它们放在一个父项目maven项目下方便。两个孩子项目并不知道父母并且彼此保持独立,但是通过将它们聚集在一个父母pom上,您可以同时方便地构建和测试它们,从而保持依赖与其依赖性相同。当您执行此操作时,您还可以为每个项目创建运行配置,以调试模式启动它们,并在其中或两者中设置断点。



父pom保持在两个项目的父文件夹中,并且不需要进入源代码管理,因为子目录不将其称为它们的父 - 它仅仅是为了方便您同时处理这两个项目。这样一个pom可能如下所示:

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi: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>任何< / artifactId>
< version> 0.0-SNAPSHOT< / version>
< packaging> pom< / packaging>
< name>所有项目< / name>
< modules>
< module> project-1-subdirectory< / module>
< module> project-2-subdirectory< / module>
< / modules>
< / 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.

解决方案

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>

这篇关于如何在Intellij中调试项目,同时在另一个项目中设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆