LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

Eclipse Photon (4.8)とJava 10でSpring Bootアプリケーションの開発環境を構築する

Posted at

概要

タイトルの通り、Eclipse Photon (4.8)とJava 10 (OpenJDK 10.0.1)を使ったSpring Bootアプリケーションの開発環境の構築手順です。

環境

  • Windows 10 Professional
  • OpenJDK 10.0.1
  • Eclipse Photon (4.8)

参考

インストール

OpenJDK

OpenJDKのJDK 10のダウンロードページより、Windows版のアーカイブファイルをダウンロードします。
tar.gzでアーカイブされているので7-zip等の対応ツールを使って適当なディレクトリへ展開します。

このディレクトリをJAVA_HOMEシステム環境変数へ、またbinディレクトリをpathシステム環境変数に追加します。
JAVA_HOMEを変えたくない場合は、Eclipseインストール後にeclipse.iniを下記のように編集してEclipse自体がこのOpenJDKを利用するようにします。

-vmargs行の直前に下記の2行を追加

eclipse.ini
省略...
-vm
D:\openjdk\jdk-10.0.1\bin\server\jvm.dll
-vmargs
省略...

Eclipse Photon

Eclipseのインストールにインストーラー版(exeファイル)ではなく、手動でインストールするzipファイル版を使用します。
Eclipse Download | The Eclipse Foundationにアクセスします。

ダウンロードボタンの下にある"Download Packages"というリンクをクリック。
(ダウンロードボタンをクリックするとインストーラー版がダウンロードされます。)

e1.png

"Eclipse IDE for Java EE Developers"の"64bit"というリンクをクリック。zipファイルのダウンロードが始まります。
この記事のときは"eclipse-jee-photon-R-win32-x86_64.zip"というファイル名です。

e2.png

ダウンロードしたzipファイルを適当な場所へ展開し、展開ディレクトリにあるeclipse.exeのショートカットをデスクトップに作成します。
Eclipseの使用メモリの割り当てを増やしたい場合は、eclipse.iniファイルの下記の行を編集します。(この例では最小1GB、最大2GBを割り当て)

-Xms1024m
-Xmx2048m

これでインストールは終了です。

Preference

Eclipseの初期設定を行います。設定は個人の好みや開発チームのルールによってさまざまだと思いますが、以下の設定は私が個人の開発時に設定する内容です。
メニューバーの"Window" → "Preference"を選択して下記の設定を行います。

General

e3.png

  • "Show heap status"にチェック

Editors

Text Editors

e4.png

  • "Show print margin"の"Print margin column"に「200」
  • "Show whitespace characters"にチェック

Configure visibility

e5.png

  • "Space"の"Leading"のチェックを外す

Workspace

e6.png

  • "Text file encoding"に「UTF-8」
  • "New text file line delimiter"に「Unix」

Java

Code Style

Formatter

Indentation

e14.png

  • "Tab policy"に「Spaces only」
  • "Indentation size"に「2」
  • "Tab size"に「2」
New Lines

e15.png

  • "After opening brace of array initializer"にチェック
  • "Before closing brace of array initializer"にチェック
  • "At end of file"にチェック
Line wrapping

e16.png

  • "Maximum line width"に「200」
Wrapping settings

Function Calls

e22.png

  • Qualified invocations
    • "Line wrapping policy:"に"Wrap all elements, expect first element if not necessary"を選択
    • "Force split, even if line shorter than maximum line width"をチェック
    • "Indentation policy:"に"Indent on column"を選択

この設定を行うと以下のようにフォーマットされます。

original
someObject.a().b().c();
format
someObject.a()
          .b()
          .c();
Comments

e20.png

  • "Maximum line width for comments"に「200」
  • "Format line comments on first column"にチェック
  • "Remove blank lines"にチェック
Off/On Tags

e18.png

  • "Enabel Off/On tags"にチェック

この設定を行うと設定したタグで囲んだ範囲をフォーマットしないようにします。

// @formatter:off

// offからonの間にあるコードはフォーマットされません

// @formatter:on

Compiler

Building

e13.png

  • "Maximum number of problems reported per compilation unit"に「1000」

Editor

Save Actions

e7.png

  • "Perform the selected actions on save"にチェック
  • "Format source code"にチェック
  • "Organize imports"にチェック
  • "Additional actions"にチェック
Configure...

"Configure..."ボタンをクリックしてさらに下記のタブで追加の設定を行います。

Code Organizing

e23.png

  • "Formatter"の"Remove trailing whitespace"にチェック

Code Style

e24.png

  • "Control statements"の"Use blocks in if/while/for/do statements"にチェック
  • "Functional interface instances"の"Convert functional interface instances"にチェック

Member Accesses

e25.png

  • "Non static accesses"の"Use 'this' qualifier for field accesses"にチェック
  • "Non static accesses"の"Use 'this' qualifier for method accesses"にチェック

Unnecessary Code

e26.png

  • "Unused code"の"Remove unused imports"にチェック
  • "Unnecessary code"の"Remove unnecessary '\$NON-NLS\$' tags"にチェック
  • "Unnecessary code"の"Remove redundant type arguments (1.7 or higher)"にチェック
  • "Unnecessary code"の"Remove redundant modifiers"にチェック

Typing

e8.png

  • "Automatically insert at correct position"の"Semicolons"にチェック

この設定はカーソルがどの位置にあっても入力したセミコロンを行末に挿入します。

JSON

JSON Files

Editor

e9.png

  • "Line width"に「120」
  • "Indent using spaces"の"Indentation size"に「2」

JavaのソースファイルではSave Actionsを有効にするとファイル保存時にフォーマットされますが、JSONやHTML、CSS、XMLファイルはSave Actionsが適用されません。このためFormattingの設定は明示的にフォーマット(Ctrl + Shift + F)しないと反映されません。

Web

CSS Files

Editor

e10.png

  • "Line width"に「120」
  • "Indent using spaces"の"Indentation size"に「2」

HTML Files

Editor

e11.png

  • "Line width"に「120」
  • "Indent using spaces"の"Indentation size"に「2」

XML

XML Files

Editor

e12.png

  • "Line width"に「120」
  • "Indent using spaces"の"Indentation size"に「2」

Terminal

e19.png

  • "Invert terminal colors"にチェック
  • "Terminal buffer lines"に「2000」

Pluginのインストール

PluginをEclipseのマーケットプレースから追加します。(lombokだけは別途インストール)

Spring Tools (aka Spring IDE and Spring Tool Suite)

Spring Framework / Spring Bootを利用したアプリケーションの開発環境を提供します。

SonarLint

ソースコードの静的解析ツールです。

Autodetect Encoding

ステータスバーにファイルのファイルエンコードと改行コードの種類を表示します。

DevStyle

Eclipseのカラーテーマです。

Lombok

  • marketplace: なし
  • version: 1.18.0

インストールはLombokのサイトよりインストールファイル(lombok.jar)をダウンロードして実行します。

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up