IntelliJ IDEA 13调试器不要在Java中针对maven项目的断点停止 [英] IntelliJ IDEA 13 debugger don't stop on breakpoint in java for maven project

查看:746
本文介绍了IntelliJ IDEA 13调试器不要在Java中针对maven项目的断点停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个断点在 System.out.println(test)命令。
我相信执行命令是由于我看到打印的字符串test。
但是断点被忽略。



断点是一个红色的圆圈,没有刻度或交叉。
我认为这是一个问题,当IDEA认为该类没有加载,而它是,因为该命令被执行。



我可以复制到各种情况:


  1. 当我按调试(使用maven配置安装exec:exec -DforkMode = never


  2. 远程调试 - 我在调试模式下在控制台中运行maven目标:



    mvnDebug install exec:exec -DforkMode = never





    mvnDebug install exec:exec



    IDEA中的远程调试配置:




    • 运行远程JVM的参数:

      -agentlib:jdwp = transport = dt_socket,server = y, suspend = n,address = 8000

    • 对于JDK 1.4.X:

      -Xdebug -Xrunjdwp:transport = dt_socket,server = y,suspend = n,address = 8000

    • 传输:Socket

    • 调试器模式:

    • 主机:localhost

    • 端口:8000

在这两种情况下,调试器只打印连接到目标VM,地址: localhost:8000',transport:'socket'



我也尝试过文件>无效缓存/重新启动
并清理构建,但断点仍然被忽略。



配置:



Ubuntu 13.10

IntelliJ IDEA终极构建133.944

Apache Maven 3.0.4

Java版本:1.7.0_51,供应商: Oracle Corporation

操作系统名称:linux,版本:3.11.0-17-generic,arch:amd64,family:unix



编辑:
pom.xml的相关部分:

 < plugin> 
< groupId> org.codehaus.mojo< / groupId>
< artifactId> exec-maven-plugin< / artifactId>
< version> 1.2.1< / version>
< configuration>
< executable> java< / executable>
< arguments>
< argument> -D - secret - 。server.configuration = / usr / local / etc< / argument>
< argument> -classpath< / argument>< classpath />
< argument> com .-- secret - 。Server< / argument>
< / arguments>
< / configuration>
< / plugin>


解决方案

我的解决方案:



考虑到您有一个依赖于系统属性的程序:

  package com.mycompany.app; 


public class App {

private static final String GREETING = System.getProperty(greeting,Hi);

public static void main(String [] args){
int x = 10;
System.out.println(GREETING);
}
}

您正在使用 exec:exec

  mvn exec:exec -Dexec.executable = java-Dexec。 args = -classpath%classpath -Dgreeting = \Hello\com.mycompany.app.App





Maven c code code code $ c $



更改您的 exec:exec 目标以启用远程调试。我正在使用 suspend = y server = n ,但可以自由配置



最后运行上面的 exec:exec 行,并随意调试应用程序:








所以基本上你需要两个运行/调试配置,使其工作: / p>


  1. 具有系统属性和JDWP的 exec:exec 的Maven配置代理配置:




  2. 远程配置作为客户端



I have a breakpoint on a line where is the System.out.println("test") command. I believe that the command is reached by execution because I see the printed string "test". But the breakpoint is ignored.

Breakpoint is a red circle all the time, without a tick or cross. I think this is an issue when IDEA thinks the class is not loaded, while it is, because the command is executed.

I can reproduce it in various circumstances:

  1. When I press debug (with maven configuration install exec:exec -DforkMode=never)

  2. Remote debugging - I run maven goal in debug mode in the console:

    mvnDebug install exec:exec -DforkMode=never

    or

    mvnDebug install exec:exec

    remote debug configuration in IDEA:

    • Arguments for running remote JVM:
      -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
    • For JDK 1.4.X:
      -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
    • Transport: Socket
    • Debugger mode: Attach
    • Host: localhost
    • Port: 8000

In both cases the debugger only prints "Connected to the target VM, address: 'localhost:8000', transport: 'socket'"

I have also tried File > Invalidate Caches / Restart and clean build, but the breakpoint is still ignored.

Configuration:

Ubuntu 13.10
IntelliJ IDEA Ultimate build 133.944
Apache Maven 3.0.4
Java version: 1.7.0_51, vendor: Oracle Corporation
OS name: "linux", version: "3.11.0-17-generic", arch: "amd64", family: "unix"

EDIT: relevant part of pom.xml:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <configuration>
    <executable>java</executable>
      <arguments>
        <argument>-D--secret--.server.configuration=/usr/local/etc</argument>
        <argument>-classpath</argument><classpath/>
        <argument>com.--secret--.Server</argument>
      </arguments>
  </configuration>
</plugin>

解决方案

My solution:

Considering that you have a program that depends on system properties:

package com.mycompany.app;


public class App {

    private static final String GREETING = System.getProperty("greeting", "Hi");

    public static void main(String[] args) {
        int x = 10;
        System.out.println(GREETING);
    }
}

And you are running it with exec:exec:

mvn exec:exec -Dexec.executable=java "-Dexec.args=-classpath %classpath -Dgreeting=\"Hello\" com.mycompany.app.App"

With some "inception magic" we can debug the process started by Mavenexec:exec.

Maven

Change your exec:exec goal to enable remote debugging. I'm using suspend=y and server=n, but feel free to configure the JDWP Agent as you please:

-agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:8000,suspend=y

This will not be passed directly to the maven JVM, instead it will be passed to exec.args which will be used by exec:exec:

mvn exec:exec -Dexec.executable=java "-Dexec.args=-classpath %classpath -agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:8000,suspend=y -Dgreeting=\"Hello\" com.mycompany.app.App"

IntelliJ IDEA

Create a Remote configuration (again I'm using a Listen strategy. You should adjust it according to your process settings):

Now toggle your breakpoints and Debug your remote configuration. Using the settings above it will wait until your process starts:

Finally run the exec:exec line above and debug your application at will:


So basically you need two "Run/Debug" configurations for this to work:

  1. A Maven configuration for exec:exec with the system properties and JDWP agent configuration:

  2. The remote configuration acting as a client.

这篇关于IntelliJ IDEA 13调试器不要在Java中针对maven项目的断点停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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