Java in Visual Studio Code

Since the company was closed, I tried to prepare the Java environment with Visual Stuido Code (hereinafter VS Code), which has been evolving all the time recently. The platform is Ubuntu 18.04. Try using Gradle as well.

VS Code installation

You can download it from the official website, but if you use Ubuntu, you can use Ubuntu Make, so you can use it. Now version 1.28.2 is installed.

umake ide visual-studio-code
umake --version
> 16.11.1

Java Extension Pack Plugin

If you enter "java" in the plugin search, a lot of it will appear, but if you include "Java Extension Pack", it seems that the following plugins are included together, so I will include this.

Reboot to reload and you're done.

Java preparation

The latest is Java 11, but this time Java 8 that was originally included is used instead. The installation procedure will be omitted here as it will hit as many times as you like if you google. Check about $ JAVA_HOME.

> /usr/lib/jvm/java-8-oracle

Gradle preparation

Official currently says 4.10.2, but I used 3.4.1 installed with apt.

apt install gradle

Project directory generation

If you have gradle, you can easily make it, so I left it to you. The point is to specify --type java-application.

mkdir project_name_dir
cd project_name_dir
gradle init --type java-application
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └──
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
    ├── main
    │   └── java
    │       └──
    └── test
	└── java

By the way, the contents of build.gradle look like this (comment line deleted)


apply plugin: 'java'
apply plugin: 'application'
repositories {
dependencies {
    compile ''
    testCompile 'junit:junit:4.12'
mainClassName = 'App'

Operation check

Try using gradle to perform tasks that you might use. It's still a template, so everything should work fine.

gradle build
gradle run
gradle check
gradle clean

VS Code settings

Select the created project directory and work.

JAVA_HOME settings

Set the value of $ JAVA_HOME in" java.home "of settings.json. You can edit the file directly or set it in the GUI.

grep java.home ~/.config/Code/User/settings.json
> "java.home": "/usr/lib/jvm/java-8-oracle"

Task settings

Set .vscode/tasks.json to execute the gradle command.

    "version": "2.0.0",
    "tasks": [
            "label": "build",
            "type": "shell",
            "command": "./gradlew build"
            "label": "run",
            "type": "shell",
            "command": "./gradlew run",
            "group": {
                "kind": "build",
                "isDefault": true
            "label": "clean",
            "type": "shell",
            "command": "./gradlew clean"
            "label": "check",
            "type": "shell",
            "command": "./gradlew check"

Executing a task

F1 key →" run task "→ Select the task set in tasks.json. You can use Ctrl + Shift + B to execute the default task run. If you set a breakpoint, it will stop at that point, so you could debug without being aware of it.


I can't say anything yet because I just touched it,

--It was not possible to refactor including the directory name such as the package name. --Shortcut keys such as code jumps are similar to Visual Studio (eclipse users may be confused) ――I want you to do your best to complement the documentation comment out.

I would like to expect future growth.

Recommended Posts

Java in Visual Studio Code
[Mac] Install Java in Visual Studio Code
Add --enable-preview option in Java in Visual Studio Code
[Mac] Install Java in Visual Studio Code (VS Code)
Java.home cannot be set in visual studio code.
Write Java8-like code in Java8
Try remote debugging of Java with Remote Containers in Visual Studio Code Insiders
Getting started with Java programs using Visual Studio Code
I couldn't type Japanese in Ubuntu20.04 + Visual Studio Code
Output settings to debug console in Visual Studio Code
Why can I develop Java with Visual Studio Code?
Build Java program development environment with Visual Studio Code
Use PlantUML with Visual Studio Code
Java Spring environment in vs Code
Build WebAPP development environment with Java + Spring with Visual Studio Code
Script Java code
Java sample code 02
Java sample code 03
Changes in Java 11
Ruby on Rails in Visual Studio Codespaces
Rock-paper-scissors in Java
Java sample code 04
All same hash code string in Java
What I learned from doing Java work with Visual Studio Code
Java sample code 01
Java character code
Pi in Java
Call Visual Recognition in Watson Java SDK
FizzBuzz in Java
Java to C and C to Java in Android Studio
A record of setting up a Java development environment with Visual Studio Code
Experience .NET 5 with Docker and Visual Studio Code
Fastest installation of Visual Studio Code on Ubuntu
Static code analysis with Checkstyle in Java + Gradle
Code to escape a JSON string in Java
Try using Sourcetrail (win version) in Java code
Try using Sourcetrail (macOS version) in Java code
[AtCoder Problem-ABC001] C-Do wind observation in Java [Code]
[Java beginner's anguish] Hard-to-test code implemented in Junit
[java] sort in list
Read JSON in Java
Make Blackjack in Java
Constraint programming in Java
Put java8 in centos7
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Comments in Java source
Azure functions in java
Format XML in Java
Simple htmlspecialchars in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
Compare Lists in Java