My thoughts on the future [Gradle app version ①]

1. 1. Introduction

I tried Spring Boot for the first time in Previous article and managed to reach the "Hello World!" Level of gradle, but after that I accidentally released Eclipse. I updated it to 2019-06, and it was troublesome to revert to the previous version, so I decided to try creating a gradle app again with the new version.

However, because the versions are different, it is still a lot of groping in the dark, such as failing what was done well so far, and it seems extremely difficult to reproduce the same thing without seeing anything, so this time As a memorandum, I would like to leave the process leading up to the creation of the app.

1.1 Goal of this article

Create Hello World for Spring Boot app with Gradle (The final goal is to create an Othello app)

1.2 version etc.

--Pleiades All in One version: Eclipse 2019-06 --STS (Spring Tools Suite) version: 4.3.1 (Spring Tools 4) --Buildship version: 3.x

1.3 Reference book

From this time, I am referring to the following books. In this article, "[Introduction](# 12 reference book)" refers to this book.

--Yano Palm Tatsu (2018) "Introduction to Spring Boot 2 Programming" Shuwa System

This is a digression, but in this article, I put an in-page link to all the words "[Introduction](# 12 reference book)" so that I can jump to this section, but the writing rules are complicated and I struggled. I have. For the links in the page, I referred to this article.

2. Until "Hello World!" Again

2.1 Installation of Pleiades All in One

I think Eclipse is very useful for Java development, but it's hard for me who is not confident in English. Therefore, I decided to use Pleiades, which installs Eclipse and at the same time translates it into Japanese.

Below is the installation procedure for Pleiades All in One.

You can install Pleiades from here. There is a blue button that says "Eclipse 2019-06", so click it. I choose the package according to the language to be developed, but if you are not worried about the capacity of your PC, choose Ultimate Full Edition. By the way, it is 2.1GB. Downloading may take some time depending on the line speed. Why did I start downloading on the Shinkansen while I was returning home, Corega Karanai

The downloaded file must be decompressed, but if it is a 2GB large file like this time, it may not be decompressed normally depending on the software. I used 7-Zip to unzip it. When unzipped, a folder named pleiades will be created, so you can save it anywhere you like (no so-called installation required). However, there is a folder called workspace that stores the source code etc. that we created, but it seems that it is variously unpleasant to put half-width spaces and full-width characters in the path of the __workspace folder, so I set the pleiades folder to C: I decided to put it directly under . Also, by default there is a workspace folder inside the pleiades folder, but I also put this workspace folder directly under C: \ (when uninstalling pleiades, I inadvertently put the source code I created in the workspace (Because it will not be erased). As for where to put the workspace folder, if the path does not include half-width spaces or full-width characters, you can decide as you like. As an aside, I'm naming it "eclipse.workspace" because I don't know what the workspace is just by naming it workspace. Also, when Eclipse starts, this workspace folder is read, so if there are many files, it will take a long time to start. So I decided to create a small workspace folder such as "eclipse.workspace.myOthello" or "eclipse.workspace.paiza.drank" under the "eclipse.workspace" folder (switching workspaces). The method will be described later).

2.2 Eclipse startup-Gradle installation

There is an eclipse folder in the pleiades folder, and eclipse.exe is in it, so double-click it to start eclipse. You will be asked for the workspace first, so let's specify the folder for the workspace created above. If you inadvertently specify a different folder for your workspace, you can switch to it later, so there is no problem. Select "Switch Workspace" from "File" on the menu bar.

By the way, in section 1.2 of "[Introduction](# 12 reference book)", the installation method of STS (Spring Tool Suite) is explained as preparation for the Spring Framework development environment, but the screen used for the explanation. Since all the captures of are written in English, this article will briefly explain in Japanese (item names translated into Japanese by pleiades).

Select "Eclipse Marketplace" from "Help" on the menu bar. Then a new screen will appear and the "Search" tab will be selected. In addition, there is an input field for the search string, so just enter "sts" and press Enter to display the search results. There should be some "Spring Tools" items in the search results.

I'm not sure about it myself, but probably because of various trials and errors, the button in the "Spring Tools 4" column in the search results was displayed as "Installed", so there is no need to install it. (Maybe you already have it installed, or the latest version of Eclipse may have Spring Tools 4 in it from the beginning). If there is a button labeled "Install" in the "Spring Tools 4" field, press it to install. Experience with Spring Tools 3 before shouldn't require complicated configuration.

Next, section 3.2 of "[Introduction](# 12 reference book)" explains how to use Gradle with STS, but it is the same because the version is different from the Eclipse I am building. Even if I do it, it doesn't work. As a result of consulting with Google teacher, I made the following trial and error. Select "Install New Software" from "Help" on the menu bar. A new window will pop up and I need to enter the site address to work with, but I got that address by following the steps below.

  1. Googling with keywords such as Buildship, gradle, and download written in "[Introduction](# 12 reference book)".
  2. The site Eclipse Buildship: Eclipse Plug-ins for Gradle will appear in the search results. Click it.
  3. There is a yellow button that says "Download Eclipse Buildship: Eclipse Plug-ins for Gradle". Press it to click GitHub eclipse site. Jump to /Installation.md).
  4. There is a table called "Update sites for Buildship 3.x" at the bottom, so for the time being, the address of the latest release of 2019-03 (https://download.eclipse.org//buildship/updates/e411/releases) Copy /3.x).

In other words, __Google teacher is always on your side! __

So, if you paste this address in the place you want to work on, the list "Buildship: Eclipse Plugin for Gradle" will be displayed in the frame below, so check it and press "Next". When the screen changes, press "Next" again. Then, the license screen will appear. Naturally, check "I accept the terms of the terms of use" and click "Finish". After a while, you will be prompted to restart Eclipse, so restart it. This completes the Gradle installation.

2.3 Creation of Spring Starter Project

Right-click in the blank area of the Package Explorer in the upper left (by default) and select New> Project. * Please note that Gradle project is not selected! The wizard selection screen will appear. At the bottom of the list, there is "Spring Boot", so select it, and then select "Spring Starter Project".

On the next setting screen, we will decide the name and group, but the __ type must be "Gradle (Buildship 3.x)" installed above __. Furthermore, on the next dependency screen, there is "Web" at the bottom, so check all the items in it and then click "Next". If you press "Finish" on the next screen, the created project will be displayed in the Package Explorer.

I will try it. Right-click on the project name displayed earlier and select "Run"-> "Spring Boot Application", and you should see the following message starting with Spring in the console tab.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.7.RELEASE)

Spring characters are hard to see when pasted ...

2.4 Hello World!

I haven't created a page to display yet, so I'll start there. Right-click on the Package Explorer name and select New → Class. Since the screen of the new Java class will be launched, name it MyOthelloController, uncheck it because it is not necessary to generate a comment, and then click "Finish".

Now that we have a simple source code with just the package and the empty class, add it here as follows:

MyOthelloController.java


package myothello.gradle;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyOthelloController {
	@RequestMapping("/")
	public String index() {
		return "Hello my othello world!";
	}
}

If you can do it so far, execute it in the same way as before, and when you access http: // localhost: 8080 / with a suitable browser, the character string "Hello my othello world!" Returned by the index method is displayed.

3. 3. Web page creation with Gradle

While referring to section 3.4 of "[Introduction](# 12 Reference Book)", we will create a Web page.

3.1 Download spring-boot-starter-thymeleaf

First, change the dependencies at the end of the build.gradle file as follows: The detailed wording is different from "[Introduction](# 12 reference book)" probably because of the version difference, but I am trying and error while reading the air.

build.gradle dependencies


dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-rest'
	implementation 'org.springframework.boot:spring-boot-starter-hateoas'
	implementation 'org.springframework.boot:spring-boot-starter-jersey'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-web-services'
	implementation 'org.springframework.boot:spring-boot-starter-webflux'
	implementation 'com.vaadin:vaadin-spring-boot-starter'
	implementation 'org.springframework.data:spring-data-rest-hal-browser'
	implementation 'org.springframework.session:spring-session-core'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'io.projectreactor:reactor-test'
	testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
}

A new line has been added that says "implementation'org.springframework.boot: spring-boot-starter-thymeleaf'". However, it seems that this library has not been downloaded yet, so right-click on the project name in Package Explorer and select Gradle → Refresh Gradle Project. This seems to update the project and include spring-boot-starter-thymeleaf. ~~ I don't understand ~~

3.2 Controller modification

Modify the controller used for "Hello World!" As follows.

MyOthelloController.java


package myothello.gradle;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MyOthelloController {
	@RequestMapping("/")
	public String myothello() {
		return "myothello";
	}
}

The RestController was imported earlier, but it has been changed to the Controller.

3.3 Creation of template file

Right-click the "src / main / resources"-> "templates" folder in the Package Explorer and select "New"-> "Other". The wizard selection screen will appear. Click "Web"-> "HTML file" and select "Next". Since you can enter the file name, enter __ "myothello" which is the same name as the method name, and then select "Next". The screen will move to the HTML template selection screen. Select "New HTML file (5)" and then click "Finish". This will create a new myothello.html, so edit it as follows.

mypthello.html


<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<title>myothello</title>
	<meta http-equiv="Content-Type" content ="text/html; charset=UTF-8" />
	<style>
	h1 { font-size:32pt; font-weight:bold; color:green; }
	body { font-size:24pt; margin:5px 25px; }
	</style>
</head>
<body>
	<h1>I'm thinking about it</h1>
	<p class="msg">It is an Othello app created with Gradle</p>
</body>
</html>

When executed, the following screen will be displayed. I don't even have an Othello board yet.

myothello1.png

As an aside, since the background color of the source editor is black, I searched for "darkest" in "Help"-> "Eclipse Marketplace" in the menu bar, and [Darkest Dark Theme](https: // marketplace). I installed something called .eclipse.org/content/darkest-dark-theme-devstyle), but I was desperate because the blue text of the CSS property value was very hard to see, probably because of my eyesight. However, you can change the color by selecting "Web"-> "CSS file"-> "Editor"-> "Syntax color specification", so it is much easier to see now. ~~ I spent a lot of time! ~~

4. Once the end

This is a continuation of the work, but since I have a sadly poor knowledge of HTML, I will implement the Othello screen while studying it. For the time being, I think Gradle's Hello World, which was the first challenge, has been cleared up, so all I have to do now is to complete the Othello app.

Recommended Posts

My thoughts on the future [Gradle app version ①]
My thoughts on the future [Preparation]
My thoughts on the equals method (Java)
My thoughts on Othello [Thinking Routine 2]
My thoughts on Othello [Thinking Routine 1]
Publish the app made with ruby on rails
Ssh login to the app server on heroku
Tips for using the Spotify app on Ubuntu
Create an app by specifying the Rails version
Install the latest version of Jenkins on Ubuntu 16
Get your version number in the Android app
Until you publish the app on the App Store by yourself
[2018 Preservation Version] Reverse Engineering Android App (.apk) on Mac
Until building Spring-Boot using Eclipse on Mac (Gradle version)
Install MySQL 5.6 on CentOS6 [How to specify the version]
[Android] Why a conflict version error occurs when loading some library on the Android app side