I want to create an environment to run Spring Boot on Windows. If I do it on Windows, I feel that it is modern to make it on WSL and develop it with VS Code, so I aim for that. First run it on Windows only, then on WSL.
Download the JDK for Windows as a zip from http://jdk.java.net/14/ and unzip it.
Move the created folder to an appropriate path. This time, I put it under C: \ Program Files \ Java \ jdk-14
.
Also, set the following in the system environment variables.
Variable | value |
---|---|
JAVA_HOME | C:\Program Files\Java\jdk-14 |
Path | Add% JAVA_HOME% bin at the beginning |
I installed the following.
Specify the JDK path in settings.json as shown below (add any other items).
{
"java.home": "C:\\Program Files\\Java\\jdk-14"
}
If you search by entering java.home
on the settings screen, a link to edit in settings.json will appear.
Open the command palette with Ctrl + Shift + P and run Create Java Project
.
After entering the save location and project name appropriately, the project will be created and opened with VS Code.
Debug with F5 and check if Hello Java
is displayed.
Open the command palette with Ctrl + Shift + P and run Spring Initiallizr: Generate a Gradle Project
.
(You can create it with Maven, but with Gradle)
Create a dependent package empty for the time being and execute it. It's OK if the Spring logo appears on the debug console and it is executed.
Install OpenJDK on WSL. It seems that OpenJDK11 can be installed with the apt command, so use this.
$ sudo apt update
$ sudo apt install -y openjdk-11-jdk
It seems old if you put it in with apt, but for the time being.
$ sudo apt install -y gradle
First, install the following.
If you type code
in the WSL terminal after installation, VS Code for the WSL environment will be launched.
In that state, install the extension installed with VS Code for Windows again.
Change the value of java.home set in settings.json.
{
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"
}
Open the command palette with Ctrl + Shift + P and run Create Java Project
.
After entering the save location and project name appropriately, the project will be created and opened with VS Code.
Debug with F5 and check if Hello Java
is displayed.
Open the command palette with Ctrl + Shift + P and run Spring Initiallizr: Generate a Gradle Project
.
Create a dependent package empty for the time being and execute it. It's OK if the Spring logo appears on the debug console and it is executed.
Create with the settings to use Spring Web when creating a project with Spring Initiallizr.
Add @RestController
annotation to Application class where main () is located, and create the following method in the class.
@GetMapping("/")
String home() {
return "Hello!";
}
Run the application, access http: // localhost: 8080 /, and if Hello!
Is displayed, it's OK.
Repository: https://github.com/stamefusa/spring-web-demo
https://qiita.com/dongsu-iis/items/6c7974022083d3036dc8
https://qiita.com/gitcho/items/a6c0bb781bc395e43ec4 https://qiita.com/gitcho/items/147a3ce2536ae3035bb8
Recommended Posts