Background/Situation
The "Java and Kotlin by IntelliJ IDEA" extension bundles a JVM debugger for both Java and Kotlin. It can launch a main class or attach to a running JVM over JDWP.
Question
How to configure launch and attach run configurations to debug Java code in Visual Studio Code using the Java and Kotlin by IntelliJ IDEA extension?
Answer
Add a debug configuration
- Open the Run and Debug view.
- Open (or create)
launch.jsonin the workspace's.vscodefolder. - Add a configuration using the IntelliJ: Launch main class or IntelliJ: Attach
to JVM snippet. All configurations use
"type": "intellij_debugger".
Launch a main class
Set "request": "launch". mainClass is required.
{
"type": "intellij_debugger",
"request": "launch",
"name": "Run main",
"mainClass": "com.example.Main"
}
| Property | Required | Description |
|---|---|---|
mainClass |
Yes | Fully-qualified name of the main class to run. |
file |
No | Path to the source file declaring the main class. Launches directly from a file, and disambiguates when the main class name is declared in more than one file. Supports ${file}. |
args |
No | Program arguments passed to the main class. |
vmArgs |
No | JVM arguments. |
classPaths |
No | Override classpath. If empty, the language server resolves it from the project model. |
modulePaths |
No | Module path entries for JPMS launches. Specified manually; the server does not resolve these automatically. |
javaExec |
No | Path to the java executable. If empty, the project SDK is used. |
cwd |
No | Working directory for the launched process. Default ${workspaceFolder}. |
env |
No | Extra environment variables for the launched process. |
Attach to a running JVM
Start the target JVM with JDWP enabled, using standard VM options such as -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005. Then set "request": "attach". port is required.
{
"type": "intellij_debugger",
"request": "attach",
"name": "Attach to JVM",
"hostName": "localhost",
"port": 5005
}
| Property | Required | Default | Description |
|---|---|---|---|
port |
Yes | 5005 |
JDWP port the JVM is listening on. |
hostName |
No | localhost |
Host the JVM is listening on. |
timeout |
No | 30000 |
Connection timeout in milliseconds. |
Breakpoints
The extension enables breakpoints for Java files. Set them in the editor gutter as usual before launching or attaching.
Comments
0 comments
Please sign in to leave a comment.