A memo to start Java programming with VS Code (2020-04 version)

Here's a note about the first steps in getting started with Java programming in VSCode. As of 2020-04, I am trying with the following versions.

--Windows 10 Pro Japanese version --AdoptOpenJDK 11 (HostSpot version)

VSCode installation

First, install VSCode.

JDK installation

Then install OpenJDK (Java Development Kit). As of 2020-04, multiple vendors such as Oracle / OpenJDK Official / AdoptOpenJDK / RedHat / Azul / AWS / BellSoft are providing binary packages respectively. I'm sure there are many opinions, but I think it's safe to use the LTS version of AdoptOpenJDK. Download and install 11 (LTS) from the AdoptOpenJDK site.

Java Extension Pack installation and java.home configuration

Install the VS Code extension "Java Extension Pack" provided by Microsoft.

You can find it by searching Java from the extended list of VSCode, and you can install it from there.

Since it is an "Extension Pack", multiple extensions for Java will be installed at once. It will take some time, so be patient with a cup of tea.

After the installation is complete, register the JDK location in VSCode. In File-> Preferences-> Settings, search for java.home in the User settings and set the directory for the installed JDK.

"java.home": "C:\\work\\jdk\\win-x64\\adopt-openjdk-hs-11.0.6_10",

How many JDK folders should I specify? However, it is OK if you specify one above the bin directory. This is recognized as the so-called JAVA_HOME.

Create a Java project

  1. Open VSCode's Command Palette (Ctrl + Shift + P) and select" Java: Create Java Project ".
  2. Select the folder where you want to create the project and enter the project name to create the Java project.
  3. src / app / App.java is created by default. If you see an overlay called "Run | Debug" above the main () method, you can start running / debugging from there. You should also be able to run it by right-clicking on App.java and clicking Run / Debug. (I forgot to try)

Create a Maven project

The Java Extension Pack also includes extensions for Maven. With Maven installed, you can open and work with your existing Maven projects in VSCode.

  1. Download and install Apache Maven.
  1. Register the Maven location in VSCode. --File-> Preferences-> Settings, search for maven.executable.path in User settings and set Maven's bin / mvn.cmd (Win) or bin / mvn (lin / mac) with full path To do. --Set maven.terminal.useJavaHome to true. This will use the JDK set in java.home when running Maven. (If you want to set the JDK for Maven execution independently, specify the JAVA_HOME environment variable separately in terminal.integrated.env etc.)
  2. Open VSCode's Command Palette (Ctrl + Shift + P) and select" Maven: Create Maven Project ".
  3. Archetype (Maven project template) Candidates are displayed in the pull-down menu, select maven-archetype-quickstart.
  4. The version will be selected, so select the latest version.
  5. Select the folder where you want to create the project.
  6. The Maven command is executed on Terminal to create the actual project based on the archetype. If you enter groupId / artifactId / version / package with an appropriate character string / value and enter Y at the confirmation, a Maven project will be created in the folder with the name specified by artifactId.
  7. Right-click on src / main / (package directory) /App.java or select" Run | Debug "on main ().
  8. You can run the test method from "Run | Debug" on the test class / method in src / test / (package directory) /AppTest.java.

More information

--Open VSCode's Command Palette (Ctrl + Shift + P) and select" Java: Getting Started "to see the tutorial. --When you open a Java project, you will also see a Java Overview. There are also various links and leads to operations, so it will be helpful. --The official VSCode Java guide is also helpful. - https://code.visualstudio.com/docs/languages/java ――VSCode officially has Java tutorials and explanations of various detailed operations, so if you are working in earnest, this is also helpful. - https://code.visualstudio.com/docs/java/java-tutorial ――If you look at the site of each Extension, you will find detailed settings for studying. - https://marketplace.visualstudio.com/items?itemName=redhat.java - https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test - https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven


--It's easy to get started with the JDK, so it's recommended for studying and getting started. --VSCode and extensions work lightly, so you don't feel the weight of major IDEs such as Eclipse. ――The first extended startup when you open Java code seems to take some time, but the lightness of VSCode is more stress-free. --Since it is based on Eclipse components, if you look at the configuration file when configuring the Java project, it is the Eclipse project itself. Experience with Eclipse may help you to troubleshoot. ――It may be necessary to investigate a little more how much it can be used for full-scale development. ――How far can VSCode follow the setting hell of Eclipse, especially for source code formats? ――How far can you follow the small undercarriage that can be easily and surely changed on the GUI setting screen with Eclipse, such as switching between multiple JDKs? ――It is recommended if you do not use it as a complicated IDE, but simply use it as an "editor".

Recommended Posts

A memo to start Java programming with VS Code (2020-04 version)
Try debugging a Java program with VS Code
Build a Java development environment with VS Code
How to build Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
[Java] How to start a new line with StringBuilder
Java build with mac vs code
Java, arrays to start with beginners
[Note] A story about changing Java build tools with VS Code
Settings to delete unused Java imports when saving with VS Code
How to open a script file from Ubuntu with VS code
Prepare Java development environment with VS Code
[Personal memo] How to interact with a random number generator in Java
A memo that enabled VS Code + JUnit 5 to be used on Windows 10
Start with a browser Ruby game programming: Introduction to Nyle-canvas (DXRuby style)
Introduction to Java development environment & Spring Boot application created with VS Code
Two ways to start a thread in Java + @
Code to escape a JSON string in Java
Using Gradle with VS Code, build Java → run
I tried to break a block with java (1)
From creating a Spring Boot project to running an application with VS Code
java competitive programming memo
Build Java development environment with VS Code on Mac
Submit a job to AWS Batch with Java (Eclipse)
How to display a browser preview in VS Code
Build Java development environment with WSL2 Docker VS Code
What I was addicted to when developing a Spring Boot application with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a private key / public key in CentOS8.2 and connect to SSH with VS Code
Create a Java (Maven) project with VS Code and develop it on a Docker container
How to lower java version
How to decompile apk file to java source code with MAC
Java program to resize a photo into a square with margins
I tried to modernize a Java EE application with OpenShift.
Docker management with VS Code
Connect to Access database with Java [UCan Access] * Set until it can be executed with VS Code
Port C code with a lot of typecasts to Swift
[Beginner] Try to make a simple RPG game with Java ①
Version control Java with SDKMAN
Format Ruby with VS Code
Create a java method [Memo] [java11]
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
Hello World with VS Code!
How to read a library from a JAR file with VS Code << How to not use Maven / Gradle >>
Java web application development environment construction with VS Code (struts2)
Java version control with jenv
Sample code to parse date and time with Java SimpleDateFormat
Connect to DB with Java
Connect to MySQL 8 with Java
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
A memo to build Jitsi Meet on Azure with docker-compose
Java study memo 2 with Progate
Java8 to start now ~ Optional ~
A story about misunderstanding how to use java scanner (memo)
I made a Dockerfile to start Glassfish 5 using Oracle Java
Code Java from Emacs with Eclim
Switch from Eclipse to VS Code
Sample code using Minio from Java
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
A story that I struggled to challenge a competition professional with Java
Android: How to deal with "Could not determine java version from '10 .0.1'"
How to switch Java version with direnv in terminal on Mac