zno2

Remote Debugging (2)

use Eclipse| a Java application

创建一个简单的maven项目

Main.java

package cn.zno;

public class Main {

    public static void main(String[] args) {
        for (String arg : args) {
            System.out.println(arg);
        }
    }

}
Main.java

pom.xml

<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>cn.zno</groupId>
    <artifactId>za</artifactId>
    <version>1.0</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
pom.xml

 

Building jar

右键项目

[INFO] Building jar: F:\e\workspacetest\za\target\za-1.0.jar

以调试模式远程启动

F:\>java -cp F:\e\workspacetest\za\target\za-1.0.jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend
=y cn.zno.Main a b c
Listening for transport dt_socket at address: 8000
_

 

 

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

现在处于挂起状态,等待debugger 启动

 

启动debugger

 

 

配置需要调试的项目,Host 和 Port

其中Host 是远程电脑的ip ,Port 为远程电脑debug模式指定的端口

然后在progress中打好断点,启动Debug,便可进入到断点调试中(如下图)

 

可以调试了~

最终结果:

F:\>java -cp F:\e\workspacetest\za\target\za-1.0.jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend
=y cn.zno.Main a b c
Listening for transport dt_socket at address: 8000
a
b
c

 

 编译时的debug信息

如果不勾选line number 调试过程中会出现这种错误:

 

 

posted on 2016-09-20 17:15  zno2  阅读(248)  评论(0编辑  收藏  举报

导航