38

Love the light-weight Visual Studio Code in OS X. Have always wanted the ability to write, debug and run standard java (NOT javascript) from VSC in OS X. Found the following extension which allows you to debug and run java from VSC:

https://marketplace.visualstudio.com/items?itemName=donjayamanne.javadebugger

Followed the directions as best as I could. Trying to run my java app, and I am getting a bunch of "error: cannot find symbol" errors in the debug-console window when I run my java app in VSC from OS X. App runs great in eclipse. What am I missing in either VSC or somewhere in OS X so I can properly run java code from VSC in OS X?

Greymarch
  • 606
  • 2
  • 7
  • 11

2 Answers2

13

I can tell you for Windows.

  1. Install Java Extension Pack and Code Runner Extension from VS Code Extensions.

  2. Edit your java home location in VS Code settings, "java.home": "C:\\Program Files\\Java\\jdk-9.0.4".

  3. Check if javac is recognized in VS Code internal terminal. If this check fails, try opening VS Code as administrator.

  4. Create a simple Java program in Main.java file as:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world");     
    }
}

Note: Do not add package in your main class.

  1. Right click anywhere on the java file and select run code.

  2. Check the output in the console.

Done, hope this helps.

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
Ashwin
  • 7,277
  • 1
  • 48
  • 70
  • 1
    Thanks for the "no package" tip, I had no idea you couldn't do that – DUUUDE123 Feb 28 '18 at 17:15
  • As indicated by @Ashwin, it is possible to debug standalone files nowadays. Even better, VS Code automatically generates the .vscode/launch.json file under the current directory. I am using VS Code version 1.32.1. – dbaltor Mar 08 '19 at 19:13
  • #3 - launch in admin mode help me with a issue where the debugger failed to launch with error message saying 'port should be > 0 or < than 65536, a very misleading error to complain for port when the debug is run on 'launch' mode. It worked when I opened vscode in admin mode. – vksp Jan 02 '20 at 04:33
0

In the extensions tab, there is Java Extension Pack published by Microsoft for Visual Studio Code. It installs 6 extensions for Java development (Language Support, Debugger, IntelliCode etc.). I used it for the first time and found it quite easy to install. enter image description here

Enis Arik
  • 665
  • 10
  • 24