You also need to specify the host when debugging remotely with Java 9 or later

environment

OS

Windows 10 64bit

Java

> java --version
openjdk 11.0.3 2019-04-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)

Implementation for verification

Folder structure


> tree /f
├─build
│  └─classes
│     └─java
│         └─main
│                 Hoge.class
└─src
    └─main
        └─java
                Hoge.java

Hoge.java


class Hoge {
    public static void main(String... args) {
        System.out.println("Hello World");
    }
}

Prior to Java 9

When debugging a Java program with Eclipse, add the following spell to the startup options.


> java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y -cp build\classes\java\main Hoge

Prior to Java 9, this allowed you to remotely connect the debugger with the 8000 port (you need to keep the port open, of course).

An error will occur if Java 9 or later

However, when I try to connect to a JVM started with this option remotely with a debugger in Java 9 or later, the following error occurs.

無題.png

In Java 9, you can no longer connect remotely if you do not specify a host

JDK 9 Release Notes | Notes and Changes

JDWP socket connector accept only local connections by default The JDWP socket connector has been changed to bind to localhost only if no ip address or hostname is specified on the agent command line. A hostname of asterisk (*) may be used to achieve the old behavior which is to bind the JDWP socket connector to all available interfaces; this is not secure and not recommended.

In Java 9, if you don't specify a host, it will automatically be bound to localhost, and it seems that you can no longer connect remotely.

You can still connect from any remote location by using *, such as ʻaddress = *: 8000`. (However, it seems that it is not recommended because it is not good for security [^ 1])

[^ 1]: It's a non-production environment at the time of connecting with the debugger, so I don't think you need to worry about it. e? Do you connect the production with a debugger? Ahh

* Try to connect by specifying

> java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=*:8000,suspend=y -cp build\classes\java\main Hoge

無題.jpg

connected.

reference

--Debug the jvm running on a non-local machine with Eclipse --TIM Labs

Recommended Posts

You also need to specify the host when debugging remotely with Java 9 or later
When you want to explicitly write OR or AND with ransack
Find out the maximum heap size when you specify the -Xmx or -XX: MaxRAM option in Java
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
How to remote debug Java 9 or later
[For beginners] When you want to say that the JVM (-D) option does not work with the java -jar command, or that the library is buggy.
[Java] Why do you bother to use the interface (Spring is also available)
Until you run a Java program with the AWS SDK local to Windows
Code used when you want to process Json with only the standard library in Java (improved version) gson unnecessary
Specify ClassPath when using jupyter + Java with WSL
When you want to use the method outside
How to delete the tweet associated with the user when you delete it at the same time
Summary of how to use the proxy set in IE when connecting with Java
What to do if you cannot execute with the command "Java package name / class name"
Code to use when you want to process Json with only standard library in Java
[Java] Get the date 10 days later with the Calendar class
HTTPS connection with Java to the self-signed certificate server
[LeJOS] Let's remotely control the EV3 motor with Java
When you want to dynamically replace Annotation in Java8
What Java engineers need to prepare for the Java 11 release
Replace only part of the URL host with java
Use JLine when you want to handle keystrokes on the console character by character in Java
When you want to implement Java library testing in Spock with multi-module in Gradle in Android Studio 3
How to reduce the load on the program even a little when combining characters with JAVA
Whether to make the server side at the time of system rebuild with Kotlin or Java