LoginSignup
6
5

More than 5 years have passed since last update.

SpringBootにWebJarsを追加してみた

Posted at

前回の続き

bootstrapやjQueryを追加したいと思いWebJarsを追加した。

環境

  • Mac High Sierra 10.13.5
  • Java 1.8.0_11
  • Maven 3.5.4
  • springboot 2.0.3

手順

WebJarsで、pom.xmlに記載する内容を確認し、追加。

pom.xml
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>bootstrap</artifactId>
    <version>4.1.1</version>
</dependency>
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.3.1</version>
</dependency>

htmlを修正。以下3行を追加し、とりあえず文字を青くした。

  <link rel="stylesheet" href="webjars/bootstrap/4.1.1/css/bootstrap.min.css" />
  <script src="webjars/bootstrap/4.1.1/js/bootstrap.min.js"></script>
  <p class="text-primary" th:text="${hello}"></p>

追加後のhtml

index.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>index page</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta charset="UTF-8" />
  <link rel="stylesheet" href="webjars/bootstrap/4.1.1/css/bootstrap.min.css" />
  <script src="webjars/bootstrap/4.1.1/js/bootstrap.min.js"></script>
</head>
<body>
  <p>index page</p>
  <p class="text-primary" th:text="${hello}"></p>
</body>
</html>

cssとjsのディレクトリを作成。

src/main/resources/static/css
src/main/resources/static/js

jarファイルを作成し、起動。
Hello World !の文字が青くなっていれば成功。

参考

6
5
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
6
5