Connect VS Code to a Linux VM running in VirtualBox or VMware or a cloud VM, via the Remote - SSH extension, then run and debug spring-petclinic remotely.
Prerequisites
- OpenSSH-compatible client (PuTTY unsupported).
- VS Code + Java and Kotlin by IntelliJ IDEA extension.
- Linux VM meeting the prerequisites.
- Install the Remote - SSH extension. Status bar gets a remote indicator; click it for Remote-SSH commands.
Create the VM in case run locally
Install VirtualBox or VMware Workstation / Fusion. Create a VM with a supported Linux distro (e.g. Ubuntu Server 22.04 LTS). See supported SSH servers.
Inside the VM with the SSH server and JDK 17:
sudo apt-get update
sudo apt-get install -y openssh-server openjdk-17-jdk git
sudo systemctl enable --now ssh
Networking
Confirm the host firewall allows the ports if needed.
One-time prepare the JAVA_HOME shell variable
Use gedit or vim, edit the file ~/.bashrc , and insert one new line at the end of the file:
export JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64.
Connect
- Status bar remote indicator → Remote-SSH: Connect to Host...
- Enter
user@<vm-ip>. - Verify first from a terminal:
ssh -p 22 user@vm-ip.- If
Connection refused, checksudo systemctl status sshinside the VM.
- If
- VS Code opens a new window, installs the VS Code Server on the host, then shows the hostname in the status bar.
Manage saved hosts from the Remote Explorer → SSH Targets. Integrated terminal (Ctrl+`) runs a bash shell on the VM. Use File → Open Folder to browse remote directories.
Clone and run spring-petclinic
On the remote terminal:
git clone https://github.com/spring-projects/spring-petclinic.git
cd spring-petclinic
./gradlew build -x test
./gradlew bootRun
App runs at http://localhost:8080 on the VM. First build downloads dependencies; give it a few minutes.
Port forwarding
Local browser can't hit the VM's localhost:8080 directly through the SSH tunnel unless VS Code forwards it. In SSH Explorer → Forwarded Ports → Forward a Port → enter 8080, name it petclinic. Then open http://localhost:8080 locally. See port forwarding docs.
(With NAT port forwarding above already exposing 8080, VS Code forwarding is optional but works alongside.)
Edit & debug
-
Open
spring-petclinic/as the workspace folder. -
The Java and Kotlin by IntelliJ IDEA extension imports the Gradle or Maven project; Inspections, hovers, and completions work as if local.
-
Open
src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java. Click the gutter next to a handler (e.g.return "welcome";) to set a breakpoint. -
Stop the running
gradlew bootRun. Then open the filePetClinicApplication.java, from the editor, there are links Run | Debug above themainmethod, click Debug to start debugging the app.
-
Trigger the breakpoint: browse
http://localhost:8080/. Inspect variables, watches, call stack.F10step,F5continue.
For more info, please check Run and debug.
End session
File → Close Remote Connection returns to local VS Code. Shut the VM down from the hypervisor UI when done.
Comments
0 comments
Please sign in to leave a comment.