简体   繁体   English

调试Maven依赖项

[英]Debugging Maven dependencies

The project "child", contains a java class: 项目“child”,包含一个java类:

package org.child;

public class Elaborate {

    public String getStr() {
    return "hello";
    }
}

And this pom.xml: 这个pom.xml:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.child</groupId>
    <artifactId>child</artifactId>
    <version>1.0-SNAPSHOT</version>


</project>

The project "parent" contains this java class: 项目“parent”包含此java类:

import org.child.Elaborate;

public class App {

    public static void main(String[] args) {


    Elaborate elaborate = new Elaborate();

    System.out.println(elaborate.getStr());
    }
}

And this pom.xml: 这个pom.xml:

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

    <dependency>
        <groupId>org.child</groupId>
        <artifactId>child</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

    </dependencies>

</project>

I'm opening the two projects into two separate Intellij windows. 我将这两个项目分成两个独立的Intellij窗口。 What I'm trying to do is debugging on both sides. 我要做的是双方调试。

However, if I run the application with the "parent", I can only debug the parent. 但是,如果我使用“父”运行应用程序,我只能调试父级。 If I put a breakpoint in the "child", the debugger doesn't stop there. 如果我在“子”中放置一个断点,调试器就不会停在那里。

Any idea on how I can do? 关于我怎么做的任何想法?

I had the same issue as you I think: 我和你想的一样有同样的问题:

I have multiple maven packages, which are separate IntelliJ 'modules'. 我有多个maven包,它们是独立的IntelliJ'模块'。

In order to debug a maven 'dependency' load it as a 'module' into the main IntelliJ 'Project' window. 为了调试maven'依赖',将它作为'模块'加载到主IntelliJ'Project'窗口中。

File > Project structure... > Project Settings > Modules 文件>项目结构...>项目设置>模块

Add > Import Module 添加>导入模块

Now navigate to your previously setup maven package, and select that folder. 现在导航到之前设置的maven包,然后选择该文件夹。

Select Import Module from External Module > Maven 从外部模块> Maven中选择导入模块

And make sure Import Maven Projects Automatically is selected. 并确保选中自动导入Maven项目

You should now see two 'modules' in the sidebar of your project. 您现在应该在项目的侧边栏中看到两个“模块”。 Setup a breakpoint in one of the dependency modules, and then Run > Debug your main module, and it should work as expected. 在其中一个依赖项模块中设置断点,然后运行>调试主模块,它应该按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM