A record of setting up a Java development environment with Visual Studio Code

When studying Java Silver, I wanted to run Java in a state close to the actual development environment, so I set the environment so that Java code can be run from VS Code and iTerm.

When running Java without using the local environment, I used a site called dokojava. This site was recommended in the book "Introduction to Java for a refreshing understanding".

Precautions when referring to this article

Develop by installing "Java Extension Pack" in Visual Stdio Code, referring to the site Create a Java (debugging) development environment with Visual Studio Code I set up the environment, but I couldn't master it, and after all, by installing OpenJDK, I was able to run Java locally.

However, wasn't the process of installing the "Java Extension Pack" on Visual Stdio Code necessary anyway? I leave it in the article because I think.

Also, OpenJDK is installed in the virtual environment of Ubuntu, but Java installed from the "Java Extension Pack" of Visual Stdio Code seems to be in the local environment.

Currently, Java in the local environment is "java version" 14.0.2 "" Java on ubuntu is "openjdk version" 1.8.0_265 "".

Is this bad ...

Settings on the Visual Studio Code side

I set it by referring to the site Create a Java (debugging) development environment with Visual Studio Code.

-First, install "Java Extension Pack" in Visual Studio Code

スクリーンショット 2020-10-03 21.39.03.png

-Open the settings from the gear mark at the bottom left and open "setting.json" スクリーンショット 2020-10-03 21.44.43.png

-Add Java settings to "setting.json" スクリーンショット 2020-10-03 21.44.15.png

"java.home": "/ Library / Java / JavaVirtualMachines / (installed JDK folder) / Contents / Home /"

And write.

Check the installed JDK folder by typing the "java -version" command in the terminal. スクリーンショット 2020-10-03 21.50.41.png

Install Java in virtual environment (ubuntu)

I installed open source Java called OpenJDK by referring to "Introduction to Java 8" of dot installation.

https://openjdk.java.net/

スクリーンショット 2020-10-03 22.05.56.png

According to the documentation

$ sudo apt-get install openjdk-8-jre

When I tried to install with the command I was impatient with an error stating that the local version may be out of date.

$ sudo apt update

I upgraded it with a command and reinstalled it, and it worked.

Move the code

If you do not use another package

javac (filename) .java

Compile with

java (filename)

Execute with.

When using a different package

In Visual Studio Code, the path from the root directory to the corresponding java file may be suggested as the package name. If you name the package accordingly, you will get a "package not found" error at compile time.

** * The directory that starts javac is the "starting point of the package"! ** **

スクリーンショット 2020-10-03 22.11.15.png

With the above directory structure, if you start javac in the java_lessons directory

-The package name of "MyApp.java" is

com.dotinstall.myapp

-The package names of "AdminUser.java" and "User.java" are

com.dotinstall.myapp.model

Will be.

Launch from terminal

Command to launch the packaged one

javac com/dotinstall/myapp/MyApp.java

The path to the java file to compile corresponds to the package name. File with entry point (main method) to compile

java com/dotinstall/myapp/MyApp

Run on

When specifying the output destination of the compiled class file

-Compile commands

javac -d (output destination) (package name) / (class name) .java

-Specify the classpath of the class to be executed

java -cd (classpath) (package name)

reference

Create a Java (debugging) development environment with Visual Studio Code

Install Java (JDK) on Mac

Recommended Posts

A record of setting up a Java development environment with Visual Studio Code
Build Java program development environment with Visual Studio Code
Build WebAPP development environment with Java + Spring with Visual Studio Code
Build a Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Prepare Java development environment with VS Code
[Oracle Cloud] Create a development environment for OCI Java SDK (Visual Studio Code, Maven, CentOS)
Spring5 MVC Web application development with Visual Studio Code Environment construction (Installation of JDK11, Maven, Tomcat, Visual Studio Code)
Try remote debugging of Java with Remote Containers in Visual Studio Code Insiders
Build Java development environment with VS Code on Mac
Getting started with Java programs using Visual Studio Code
Why can I develop Java with Visual Studio Code?
Build Java development environment with WSL2 Docker VS Code
How to build Java development environment with VS Code
Java in Visual Studio Code
I tried "Visual Studio Code Installer for Java" which can create Java development environment immediately
I tried to create a java8 development environment with Chocolatey
Java web application development environment construction with VS Code (struts2)
Use PlantUML with Visual Studio Code
[Eclipse Java] Development environment setting memo
Prepare Java development environment with Atom
Java development environment (Mac, VS Code)
What I learned from doing Java work with Visual Studio Code
I tried to take a look at the flow of Android development environment construction with Android Studio
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
[Processing x Java] Construction of development environment
Build a PureScript development environment with Docker
Let's create a Java development environment (updating)
Build a Java development environment on Mac
Build a Wordpress development environment with Docker
[Mac] Install Java in Visual Studio Code
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 1/3 [Preparation]
Spring5 MVC Web App Development with Visual Studio Code Hello World Creation
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
Spring5 MVC web application development with Visual Studio Code SQL Server connection
Build a hot reload development environment with Docker-compose using Realize of Go
Creating a java web application development environment with docker for mac part1
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Spring5 MVC Web application development with Visual Studio Code Maven template creation
Create a java web application development environment with docker for mac part2
Introduction to Java development environment & Spring Boot application created with VS Code
Experience .NET 5 with Docker and Visual Studio Code
Let's get started with Java-Create a development environment ②
Fastest installation of Visual Studio Code on Ubuntu
Let's get started with Java-Create a development environment ①
Add --enable-preview option in Java in Visual Studio Code
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Build a WordPress development environment quickly with Docker
[Java] Explanation of Strategy pattern (with sample code)
Java development environment
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 2/3 [Page creation 1/2]
Spring5 MVC Web application development with Visual Studio Code Spring Security usage 3/3 [Page creation 2/2]
[Win10] Build a JSF development environment with NetBeans
Prepare a scraping environment with Docker and Java
A reminder of Docker and development environment construction
Build a development environment for Docker, java, vscode
Try debugging a Java program with VS Code
[Mac] Install Java in Visual Studio Code (VS Code)
Create a Spring Boot development environment with docker
The procedure I did when I prepared the environment of gradle + Java with VS Code (Windows 10)
Learn the meaning of "passing the PATH" by building a Java development environment on Mac