It was necessary to prepare the environment for the subject, so I made a note of it until it started working. I'm not very familiar with this area, so there may be some deficiencies, but I hope it helps.
There are several types of JDK, but here we will use OpenJDK. https://openjdk.java.net/ As of October 2020, the latest was JDK15, so download this for Windows. Download for Windows, unzip it, and place the "jdk-15" that appears in any folder.
Install the Java Extension Pack from the VS Code extension.
After installation, display the settings with
Ctrl +,, search for "Java: Home", click "Edit with settings.json", and specify the folder of "jdk-15" placed above.
At this time, it is necessary to overlap two backslashes as follows.
Ctrl + Shift + P
When I select a folder and try to create a Java project, I get an error that the environment variable
JAVA_HOME is not set.
Error: JAVA_HOME not found in your environment. Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
Start PowerShell with administrator privileges and set the Java storage path in the system environment variable
JAVA_HOME with the following command.
[System.Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\hoge\hoge\jdk-15", "Machine")
Then restart VS Code. (The above error was not resolved without rebooting.)
Generate a Java project again and set various IDs.
Define value for property 'groupId': (Specify what you want to be the package name) Define value for property 'artifactId': (Specify what you want to be the jar name) Define value for property 'version' 1.0-SNAPSHOT: : (Leave the default value without entering) Define value for property 'package' (What you entered in groupId): : (Leave the default value without entering)
Open the generated Java project folder with VS Code, and the project creation is complete.
In the Explorer pane of VS Code, right-click App.java under the src folder and execute "Run" to build it, and "Hello World!" Is output to the terminal.
If you created a Java project as it is, JUnit4 was used, so change it to JUnit5. Since there is a sample project of JUnit5, change the pom.xml of the created project by referring to the pom.xml. https://raw.githubusercontent.com/junit-team/junit5-samples/r5.7.0/junit5-jupiter-starter-maven/pom.xml
This time I changed it like this.
+ <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>5.7.0</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies>
When you save pom.xml, a dialog asking if you want to synchronize is displayed. Click "Now" to synchronize. You can now use JUnit 5.