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

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

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

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

Java

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

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Gradle

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

Spring Boot

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

Q&A

0回答

2712閲覧

【SpringBoot】Eclipseから作成したjarファイルが実行できない

Nattsu

総合スコア12

JAR

JAR(又はJava ARchive)はコンパイルされた複数のJavaバイトコード及び関連ファイルのリソースを一つのファイルに統合したものです。JARファイルはZIPファイルのフォーマットで構築されています。

Java

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

Eclipse

Eclipseは、IBM社で開発された統合開発環境のひとつです。2001年11月にオープンソース化されました。 たくさんのプラグインがあり自由に機能を追加をすることができるため、開発ツールにおける共通プラットフォームとして位置づけられています。 Eclipse自体は、Javaで実装されています。

Gradle

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

Spring Boot

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

0グッド

1クリップ

投稿2019/06/27 07:04

編集2019/06/27 08:31

初めて質問します。
不足している情報や不手際がありましたら申し訳ありません。
コメント欄にて確認していただけると幸いです。

前提・実現したいこと

Spring Bootフレームワークを用いて、webアプリケーションを開発しています。
このアプリケーションをjarで吐き出して実行しても動かず困っています。

cmd

1> java -jar example-ver-0.1.jar

将来的には、EC2に乗せて動かしたいと思っています。

開発環境であるEclipse上では動いており、パッケージにする際に何かが足りていないのでは、と考えています。

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

[main] INFO com.example.exampleApplication - Starting exampleApplication on xxx-001 with PID 13964 (C:\pleiades\workspace\example-ver\build\libs\example-ver-0.1.jar started by xxx in c:\pleiades\workspace\example-ver\build\libs) [main] DEBUG com.example.exampleApplication - Running with Spring Boot, Spring [main] INFO com.example.exampleApplication - No active profile set, falling back to default profiles: default [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.example.exampleApplication [main] DEBUG org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@376b4233 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/domain/repository/XXX_Repository.class] ・・・ [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/service/XXX_Service.class] ・・・ [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/web/XXX_Controller.class] ・・・ [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalPersistenceAnnotationProcessor' [main] DEBUG org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@70e9c95d] [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. [main] ERROR org.springframework.boot.SpringApplication - Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) at com.example.exampleApplication.main(exampleApplication.java:27) Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:206) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ... 8 common frames omitted

該当のソースコード

メインのクラスは下記のとおりです

java

1 2package com.example; 3 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.SpringBootApplication; 6import org.springframework.boot.autoconfigure.domain.EntityScan; 7import org.springframework.boot.builder.SpringApplicationBuilder; 8import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 9 10@SpringBootApplication 11@EntityScan("com.example") 12public class MainApp extends SpringBootServletInitializer { 13 14 @Override 15 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 16 return application.sources(MainApp.class); 17 } 18 19 public static void main(String[] args) { 20 SpringApplication.run(MainApp.class, args); 21 } 22 23} 24

build.gradle

buildscript { ext { springBootVersion = '2.1.6.RELEASE' } repositories { mavenCentral() jcenter() maven { url "https://repo.spring.io/release/" } maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } plugins { id 'java' id 'eclipse' id 'org.springframework.boot' version '2.1.6.RELEASE' id 'io.spring.dependency-management' version '1.0.6.RELEASE' id 'jacoco' id 'groovy' id 'com.github.ben-manes.versions' version '0.14.0' id 'com.github.johnrengelman.shadow' version '4.0.2' } apply plugin: 'maven' apply plugin: 'application' sourceCompatibility = '1.8' targetCompatibility = '1.8' wrapper { gradleVersion = "5.4" distributionType = Wrapper.DistributionType.ALL } springBoot { buildInfo() } group = 'com.example' version = '0.1' mainClassName ="com.example.MainApp" defaultTasks 'shadowJar' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() mavenLocal() } dependencies { implementation 'org.webjars:jquery:3.4.1' implementation 'org.webjars:jquery-ui:1.12.1' implementation 'org.webjars:popper.js:1.15.0' implementation 'org.webjars:bootstrap:4.1.3' implementation 'com.amazonaws:aws-java-sdk:+' implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' // implementation 'org.springframework.boot:spring-boot-starter-security' compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } jacoco { toolVersion = "0.8.3" reportsDir = file("$buildDir/customJacocoReportDir") } jacocoTestReport { reports { xml.enabled false csv.enabled false html.destination file("${buildDir}/jacocoHtml") } } shadowJar { mergeServiceFiles() zip64 true exclude 'META-INF/INDEX.LIST' exclude 'META-INF/*.SF' exclude 'META-INF/*.DSA' exclude 'META-INF/*.RSA' } jar{ manifest { attributes "Main-Class" : "com.example.MainApp" } }

試したこと

jarファイルの作成手順として、
対象プロジェクト右クリック-[実行]-[実行構成]-[Gradle Project]より
Gradleタスク "build"
で実行し、jarファイルを作成しております。

下記質問の答えが近いのではと考え、@Beanの手動設定等調べましたが、すべてのソースにおいて問題なく動作しているようです(Eclipse上で問題なく動いていることから、アノテーションが不足しているということは考えにくいと思っています

参考質問サイト

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

Eclipse:pleiades
Spring Boot:2.1.6
Gradle:5.2.1

よろしくお願いいたします。

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

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

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

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

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

m.ts10806

2019/06/27 07:58

>springframework version:2.1.4 本体は大体4か5だと思います。 コードからするとSpring Bootのバージョンではないでしょうか? (とするとおそらくSpring本体は5のはず)
Nattsu

2019/06/27 08:30

確認しました。 springbootのバージョンが2.1.4でした… ※色々調べたらそもそも2.1.6で作ってるのに定義間違っていたので2.1.6に修正しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問