Now that we have built a Java development environment on Mac, the steps are summarized below. It describes until "Hello World" is output.
In Pleiades All in One Eclipse, with the automatic default setting function, The path of the compiler etc. is set automatically without depending on the existing JDK environment. Therefore, you don't need a JDK, but if you are interested in an older version of the JDK, Please delete it in advance according to the procedure of reference information (How to uninstall JDK).
Download Pleiades All in One Eclipse from the following site. http://mergedoc.osdn.jp/
(1) Select Eclipse 4.7 Oxygen.
(2) Select Mac 64bit (Full Edition) and Java.
(1) Execute pleiades-4.7.2-java-mac-jre_20171225.dmg. (2) Drag and drop it on Applications.
At the first startup, a warning "Cannot open because the developer has not been confirmed" may be displayed.
In that case, if you right-click to open it, the following dialog will be displayed, so Click "Open". From the second time onward, this warning will not be displayed.
Select any directory for the workspace.
(1) Select Help → Eclipse Marketplace from the menu.
(2) Search for "STS" and install.
(3) On the confirmation screen of the selected feature, just press the confirmation button. (4) On the license review screen, select "I accept the terms of the terms of use" and click the Finish button.
This is because the locally cached server information is out of date. Please update the server information according to the procedure of reference information (update server information). After updating, if you install again, you can install without error.
(5) Right-click on Package Explorer → New → Other You can see that Spring and Spring Boot have been added.
Created in the Spring Starter project.
(1) Creating a project File → New → Other → Select Spring Starter Project (2) Except for selecting "Gradle (Buildship 2.x)" as the type, proceed to "Next" with the default settings.
(3) Select "Web" and proceed to "Next".
(4) Finally, a confirmation screen will be displayed. Click the "Finish" button.
(1) Execution of the project Right-click on the project → Run → Spring Boot Application. (2) Check the console It is successful if the following log is output to the console.
(3) Check the default page Go to localhost: 8080.
An error will occur because the default web page is not prepared.
(1) Creating a class File → New → Select Class (2) Here, create it with the name "HelloController". Other than the name, it remains the default.
The following program is completed.
HelloController.java
package com.example.demo;
public class HelloController {
}
(3) Change to output "Hello World".
HelloController.java
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Hello World";
}
}
(4) Re-execute the project and access localhost: 8080.
application.properties
server.port=8081
By rerunning the project and accessing localhost: 8081, Hello World is displayed.
(1) Confirmation of existing environment Run the following command: $ /usr/libexec/java_home -V
Matching Java Virtual Machines (2): 1.8.0_151, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home 1.7.0_65, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
In the above example, two JDKs are installed.
(2) Uninstall the JDK To uninstall, execute the rm command. For the path to be deleted, specify the "/ Library / Java ~" part output by the confirmation command. Also, add sudo to the head because it can only be deleted with administrator privileges. (A password will be required, so enter the administrator password.)
An example of the above is shown below. $ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home Password: $ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home
(3) Check the environment after uninstalling Execute the following command in the same way as (1). $ /usr/libexec/java_home -V
Unable to find any JVMs matching version "(null)". Matching Java Virtual Machines (0):
Default Java Virtual Machines (0):
No Java runtime present, try --request to install.
(1) Select Eclipse → Preferences from the menu. (2) From the left panel, select a software site for which installation / update is available.
(3) Select the location where the error occurred and press the reload button. In this example, "SpringSource Update Site for Eclipse 4.7" is the location that caused the error.
There are two types of Spring projects. (1) Spring Legacy Project It is used for all programs that use Spring Framework. Select this if you do not want to use the Spring Boot function. (2) Spring Starter Project It is used when creating an application that uses the Spring Boot function.
There are the following types of Gradle plug-ins in Eclipse. ・ Gradle IDE Plugin distributed by Nodeclipse Install from Eclipse Marketplace. ・ STS ・ Buildship The official Gradle plugin Buildship has been released on eclipse.org. Also added to Pleiades All in One.
If you have two installed, you can choose when creating a Spring project. ・ Gradle (STS) ・ Gradle (Buildship)
https://qiita.com/cypher256/items/233795f4fc58a704ee47
Recommended Posts