質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

2回答

1405閲覧

SpringBootでのデスクトップアプリケーションの配布について

programquestion

総合スコア11

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

IntelliJ IDEA

IntelliJ IDEA(インテリジェイ アイディア)は、JetBrains社が開発した、 JavaやScalaなどで利用される統合開発環境です。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2023/01/13 08:02

編集2023/01/14 02:49

前提

Springbootでアプリケーションの開発をおこなっております。
intellijで開発をおこなっており、gradleを活用しております。

実現したいこと

デスクトップアプリケーションとして配布をしたいと考えております。

発生している問題・エラーメッセージ

配布するにあたって、./gradlew buildでfat jarを作成し、それをjava -jarコマンドで実行すると、localhostにアクセスした際に、以下のエラーが発生します。

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Jan 13 16:54:40 JST 2023
There was an unexpected error (type=Internal Server Error, status=500).

ERROR 21449 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index], template might not exist or might not be accessible by any of the configured Template Resolvers

該当のソースコード

build.gradleは以下のようになっております。

plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
}

jar {
manifest {
attributes "Main-Class": "com.test.subSystem.SubSystemApplication"
}
}

group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.2.3'
implementation fileTree(dir: 'rapidreport', include: ['*.jar'])
}

tasks.named('test') {
useJUnitPlatform()
}

試したこと

intellij上のデバックでは問題なく動作しております。
また、./gradlew bootrunでも同様に動作しております。

補足情報(FW/ツールのバージョンなど)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

shiketa

2023/01/13 08:24

# デスクトップアプリケーションでWebサービスを立ち上げる、というあたりは危険な香りがして大丈夫かしらとおもいますが、気にしないことにします。 gradlew bootJar でjarファイルを作ればいいのではないでしょうか。
programquestion

2023/01/13 08:35

将来的にWebアプリケーションに組み込む想定で、とりあえずのデスクトップアプリの提供を予定しております。 ./gradlew bootJarでjarファイルを作成してみましたが、同じエラーが発生してしまいました。。
guest

回答2

0

自己解決

application.propertiesを修正したことにより、解決することができました。

修正前
spring.thymeleaf.prefix=file:src/main/resources/templates/

修正後
spring.thymeleaf.prefix=classpath:/templates/

投稿2023/01/14 03:13

programquestion

総合スコア11

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

  1. Spring Initializrでプロジェクトを作成する。

https://start.spring.io/#!type=gradle-project-kotlin&language=kotlin&platformVersion=3.0.1&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=web,h2,data-jdbc,thymeleaf

  1. 以下のパッチを適用
  2. ./gradlew bootJar
  3. java -jar build/libs/demo-0.0.1-SNAPSHOT.jar

実行するとウィンドウが開く。すぐにボタンを押下すると例外が発生する。
しばらくするとWebサーバが起動される。その後ボタンを押下するとコンテンツを取得できる。

diff

1Subject: [PATCH] . 2--- 3Index: src/main/kotlin/com/example/demo/DemoApplication.kt 4IDEA additional info: 5Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 6<+>UTF-8 7=================================================================== 8diff --git a/src/main/kotlin/com/example/demo/DemoApplication.kt b/src/main/kotlin/com/example/demo/DemoApplication.kt 9--- a/src/main/kotlin/com/example/demo/DemoApplication.kt (revision 2ba6120f0a6a56b37db9c33087de6b774212c1f6) 10+++ b/src/main/kotlin/com/example/demo/DemoApplication.kt (date 1673613856935) 11@@ -2,10 +2,12 @@ 12 13 import org.springframework.boot.autoconfigure.SpringBootApplication 14 import org.springframework.boot.runApplication 15+import javax.swing.SwingUtilities 16 17 @SpringBootApplication 18-class DemoApplication 19+class DemoApplication {} 20 21 fun main(args: Array<String>) { 22- runApplication<DemoApplication>(*args) 23+ SwingUtilities.invokeLater { SwingApp() } // Start UI 24+ runApplication<DemoApplication>(*args) // Start Web 25 } 26Index: src/main/resources/templates/index.html 27IDEA additional info: 28Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 29<+>UTF-8 30=================================================================== 31diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html 32new file mode 100644 33--- /dev/null (date 1673612608877) 34+++ b/src/main/resources/templates/index.html (date 1673612608877) 35@@ -0,0 +1,11 @@ 36+<!doctype html> 37+<html xmlns:th="http://www.thymeleaf.org"> 38+<head> 39+ <meta charset="UTF-8" /> 40+ <title>Hello Thymeleaf</title> 41+</head> 42+<body> 43+<h1>Hello Thymeleaf</h1> 44+<h1 th:text="${message}"></h1> 45+</body> 46+</html> 47\ No newline at end of file 48Index: src/main/kotlin/com/example/demo/SwingApp.kt 49IDEA additional info: 50Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP 51<+>UTF-8 52=================================================================== 53diff --git a/src/main/kotlin/com/example/demo/SwingApp.kt b/src/main/kotlin/com/example/demo/SwingApp.kt 54new file mode 100644 55--- /dev/null (date 1673613856919) 56+++ b/src/main/kotlin/com/example/demo/SwingApp.kt (date 1673613856919) 57@@ -0,0 +1,35 @@ 58+package com.example.demo 59+ 60+import java.awt.FlowLayout 61+import java.net.URL 62+import java.nio.file.Files 63+import java.time.LocalTime 64+import javax.swing.JButton 65+import javax.swing.JFrame 66+import javax.swing.JLabel 67+import javax.swing.JTextArea 68+ 69+class SwingApp : JFrame() { 70+ init { 71+ this.contentPane.layout = FlowLayout() 72+ this.contentPane.add(JLabel("${LocalTime.now()}")) 73+ val textArea = JTextArea() 74+ val button = JButton("get") 75+ button.addActionListener({ ev -> 76+ try { 77+ val url = URL("http://localhost:8080/") 78+ val tmp = Files.createTempFile("tmp", "xxx") 79+ Files.deleteIfExists(tmp) 80+ Files.copy(url.openStream(), tmp) 81+ val content = Files.readAllLines(tmp).joinToString("\n") 82+ textArea.text = content 83+ } catch (e: Exception) { 84+ textArea.text = e.stackTraceToString() 85+ } 86+ }) 87+ this.contentPane.add(button) 88+ this.contentPane.add(textArea) 89+ this.setSize(600, 400) 90+ this.isVisible = true 91+ } 92+} 93\ No newline at end of file

投稿2023/01/13 12:52

shiketa

総合スコア3971

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

programquestion

2023/01/14 03:00

テスト動作もいただき、ありがとうございます。 Webサーバの起動の時間を待つことがポイントとしてあげていただいたのかと思いますが、10分くらい待っても同じエラーが表示されてしまいました。 thymeleaf周りのエラーなのかわかりませんが、その線でも調べてみたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問